Module rearrangement and doxygen documentification. API break.

develop
Petr Mrázek 2011-03-18 11:09:26 +01:00
parent b94ddf50d0
commit a6c724bfb5
19 changed files with 646 additions and 605 deletions

@ -52,7 +52,6 @@ include/dfhack/modules/Gui.h
include/dfhack/modules/Items.h include/dfhack/modules/Items.h
include/dfhack/modules/Maps.h include/dfhack/modules/Maps.h
include/dfhack/modules/Materials.h include/dfhack/modules/Materials.h
include/dfhack/modules/Position.h
include/dfhack/modules/Translation.h include/dfhack/modules/Translation.h
include/dfhack/modules/Vegetation.h include/dfhack/modules/Vegetation.h
include/dfhack/modules/WindowIO.h include/dfhack/modules/WindowIO.h

@ -163,7 +163,6 @@ MODULE_GETTER(Maps);
MODULE_GETTER(Gui); MODULE_GETTER(Gui);
MODULE_GETTER(WindowIO); MODULE_GETTER(WindowIO);
MODULE_GETTER(World); MODULE_GETTER(World);
MODULE_GETTER(Position);
MODULE_GETTER(Materials); MODULE_GETTER(Materials);
MODULE_GETTER(Items); MODULE_GETTER(Items);
MODULE_GETTER(Translation); MODULE_GETTER(Translation);

@ -207,12 +207,10 @@ bool NormalProcess::resume()
perror("ptrace resume error"); perror("ptrace resume error");
return false; return false;
} }
int status;
suspended = false; suspended = false;
return true; return true;
} }
bool NormalProcess::attach() bool NormalProcess::attach()
{ {
int status; int status;

@ -168,12 +168,6 @@ union t_itemflags
naked_itemflags bits; naked_itemflags bits;
}; };
//cooked
struct t_viewscreen
{
int32_t type;
//There is more info in these objects, but I don't know what it is yet
};
struct t_note struct t_note
{ {

@ -31,11 +31,11 @@ namespace DFHack
struct t_construction struct t_construction
{ {
//0 //0
uint16_t x; uint16_t x; /*!< X coordinate */
uint16_t y; uint16_t y; /*!< Y coordinate */
// 4 // 4
uint16_t z; uint16_t z; /*!< Z coordinate */
e_construction_base form : 16; e_construction_base form : 16; /*!< type of item the construction is made of */
// 8 // 8
uint16_t unk_8; // = -1 in many cases uint16_t unk_8; // = -1 in many cases
uint16_t mat_type; uint16_t mat_type;

@ -6,187 +6,111 @@
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h" #include "dfhack/DFModule.h"
#include "dfhack/modules/Items.h" #include "dfhack/modules/Items.h"
/**
* \defgroup grp_creatures Creatures module parts
* @ingroup grp_modules
*/
namespace DFHack namespace DFHack
{ {
/* /**
bits: * easy access to first crature flags block
* \ingroup grp_creatures
0 Can the dwarf move or are they waiting for their movement timer */
1 Dead (might also be set for incoming/leaving critters that are alive)
2 Currently in mood
3 Had a mood
4 "marauder" -- wide class of invader/inside creature attackers
5 Drowning
6 Active merchant
7 "forest" (used for units no longer linked to merchant/diplomacy, they just try to leave mostly)
8 Left (left the map)
9 Rider
10 Incoming
11 Diplomat
12 Zombie
13 Skeleton
14 Can swap tiles during movement (prevents multiple swaps)
15 On the ground (can be conscious)
16 Projectile
17 Active invader (for organized ones)
18 Hidden in ambush
19 Invader origin (could be inactive and fleeing)
20 Will flee if invasion turns around
21 Active marauder/invader moving inward
22 Marauder resident/invader moving in all the way
23 Check against flows next time you get a chance
24 Ridden
25 Caged
26 Tame
27 Chained
28 Royal guard
29 Fortress guard
30 Suppress wield for beatings/etc
31 Is an important historical figure
*/
struct naked_creaturflags1
{
unsigned int move_state : 1; // Can the dwarf move or are they waiting for their movement timer
unsigned int dead : 1; // might also be set for incoming/leaving critters that are alive
unsigned int has_mood : 1; // Currently in mood
unsigned int had_mood : 1; // Had a mood
unsigned int marauder : 1; // wide class of invader/inside creature attackers
unsigned int drowning : 1;
unsigned int merchant : 1; // active merchant
unsigned int forest : 1; // used for units no longer linked to merchant/diplomacy, they just try to leave mostly
unsigned int left : 1; // left the map
unsigned int rider : 1;
unsigned int incoming : 1;
unsigned int diplomat : 1;
unsigned int zombie : 1;
unsigned int skeleton : 1;
unsigned int can_swap : 1; // Can swap tiles during movement (prevents multiple swaps)
unsigned int on_ground : 1; // can be conscious
unsigned int projectile : 1;
unsigned int active_invader : 1; // for organized ones
unsigned int hidden_in_ambush : 1;
unsigned int invader_origin : 1; // could be inactive and fleeing
unsigned int coward : 1; // Will flee if invasion turns around
unsigned int hidden_ambusher : 1; // maybe
unsigned int invades : 1; // Active marauder/invader moving inward
unsigned int check_flows : 1; // Check against flows next time you get a chance
// 0100 0000 - 8000 0000
unsigned int ridden : 1;
unsigned int caged : 1;
unsigned int tame : 1;
unsigned int chained : 1;
unsigned int royal_guard : 1;
unsigned int fortress_guard : 1;
unsigned int suppress_wield : 1; // Suppress wield for beatings/etc
unsigned int important_historical_figure : 1; // Is an important historical figure
};
union t_creaturflags1 union t_creaturflags1
{ {
uint32_t whole; uint32_t whole;/*!< Access all flags as a single 32bit number. */
naked_creaturflags1 bits; struct
}; {
unsigned int move_state : 1; /*!< 0 : Can the dwarf move or are they waiting for their movement timer */
/* unsigned int dead : 1; /*!< 1 : Dead (might also be set for incoming/leaving critters that are alive) */
bits: unsigned int has_mood : 1; /*!< 2 : Currently in mood */
unsigned int had_mood : 1; /*!< 3 : Had a mood already */
0 Swimming
1 Play combat for sparring unsigned int marauder : 1; /*!< 4 : wide class of invader/inside creature attackers */
2 Do not notify about level gains (for embark etc) unsigned int drowning : 1; /*!< 5 : Is currently drowning */
3 Unused unsigned int merchant : 1; /*!< 6 : An active merchant */
unsigned int forest : 1; /*!< 7 : used for units no longer linked to merchant/diplomacy, they just try to leave mostly */
4 Nerves calculated
5 Body part info calculated unsigned int left : 1; /*!< 8 : left the map */
6 Is important historical figure (slight variation) unsigned int rider : 1; /*!< 9 : Is riding an another creature */
7 Has been killed by kill function (slightly different from dead, not necessarily violent death) unsigned int incoming : 1; /*!< 10 */
unsigned int diplomat : 1; /*!< 11 */
8 Must be forgotten by forget function (just cleanup)
9 Must be deleted (cleanup) unsigned int zombie : 1; /*!< 12 */
10 Recently forgotten (cleanup) unsigned int skeleton : 1; /*!< 13 */
11 Offered for trade unsigned int can_swap : 1; /*!< 14: Can swap tiles during movement (prevents multiple swaps) */
unsigned int on_ground : 1; /*!< 15: The creature is laying on the floor, can be conscious */
12 Trade resolved
13 Has breaks unsigned int projectile : 1; /*!< 16: Launched into the air? Funny. */
14 Gutted unsigned int active_invader : 1; /*!< 17: Active invader (for organized ones) */
15 Circulatory spray unsigned int hidden_in_ambush : 1; /*!< 18 */
unsigned int invader_origin : 1; /*!< 19: Invader origin (could be inactive and fleeing) */
16 Locked in for trading (it's a projectile on the other set of flags, might be what the flying was)
17 Marked for slaughter unsigned int coward : 1; /*!< 20: Will flee if invasion turns around */
18 Underworld creature unsigned int hidden_ambusher : 1; /*!< 21: Active marauder/invader moving inward? */
19 Current resident unsigned int invades : 1; /*!< 22: Marauder resident/invader moving in all the way */
unsigned int check_flows : 1; /*!< 23: Check against flows next time you get a chance */
20 Marked for special cleanup as unused load from unit block on disk
21 Insulation from clothing calculated unsigned int ridden : 1; /*!< 24*/
22 Uninvited guest unsigned int caged : 1; /*!< 25*/
23 Visitor unsigned int tame : 1; /*!< 26*/
unsigned int chained : 1; /*!< 27*/
24 Inventory order calculated
25 Vision -- have good part unsigned int royal_guard : 1; /*!< 28*/
26 Vision -- have damaged part unsigned int fortress_guard : 1; /*!< 29*/
27 Vision -- have missing part unsigned int suppress_wield : 1; /*!< 30: Suppress wield for beatings/etc */
unsigned int important_historical_figure : 1; /*!< 31: Is an important historical figure */
28 Breathing -- have good part } bits;
29 Breathing -- having a problem
30 Roaming wilderness population source
31 Roaming wilderness population source -- not a map feature
*/
struct naked_creaturflags2
{
unsigned int swimming : 1;
unsigned int sparring : 1;
unsigned int no_notify : 1; // Do not notify about level gains (for embark etc)
unsigned int unused : 1;
unsigned int calculated_nerves : 1;
unsigned int calculated_bodyparts : 1;
unsigned int important_historical_figure : 1; // slight variation
unsigned int killed : 1; // killed by kill() function
unsigned int cleanup_1 : 1; // Must be forgotten by forget function (just cleanup)
unsigned int cleanup_2 : 1; // Must be deleted (cleanup)
unsigned int cleanup_3 : 1; // Recently forgotten (cleanup)
unsigned int for_trade : 1; // Offered for trade
unsigned int trade_resolved : 1;
unsigned int has_breaks : 1;
unsigned int gutted : 1;
unsigned int circulatory_spray : 1;
unsigned int locked_in_for_trading : 1;
unsigned int slaughter : 1; // marked for slaughter
unsigned int underworld : 1; // Underworld creature
unsigned int resident : 1; // Current resident
unsigned int cleanup_4 : 1; // Marked for special cleanup as unused load from unit block on disk
unsigned int calculated_insulation : 1; // Insulation from clothing calculated
unsigned int visitor_uninvited : 1; // Uninvited guest
unsigned int visitor : 1; // visitor
unsigned int calculated_inventory : 1; // Inventory order calculated
unsigned int vision_good : 1; // Vision -- have good part
unsigned int vision_damaged : 1; // Vision -- have damaged part
unsigned int vision_missing : 1; // Vision -- have missing part
unsigned int breathing_good : 1; // Breathing -- have good part
unsigned int breathing_problem : 1; // Breathing -- having a problem
unsigned int roaming_wilderness_population_source : 1;
unsigned int roaming_wilderness_population_source_not_a_map_feature : 1;
}; };
union t_creaturflags2 union t_creaturflags2
{ {
uint32_t whole; uint32_t whole; /*!< Access all flags as a single 32bit number. */
naked_creaturflags2 bits; struct
{
unsigned int swimming : 1;
unsigned int sparring : 1;
unsigned int no_notify : 1; /*!< Do not notify about level gains (for embark etc)*/
unsigned int unused : 1;
unsigned int calculated_nerves : 1;
unsigned int calculated_bodyparts : 1;
unsigned int important_historical_figure : 1; /*!< Is important historical figure (slight variation)*/
unsigned int killed : 1; /*!< Has been killed by kill function (slightly different from dead, not necessarily violent death)*/
unsigned int cleanup_1 : 1; /*!< Must be forgotten by forget function (just cleanup) */
unsigned int cleanup_2 : 1; /*!< Must be deleted (cleanup) */
unsigned int cleanup_3 : 1; /*!< Recently forgotten (cleanup) */
unsigned int for_trade : 1; /*!< Offered for trade */
unsigned int trade_resolved : 1;
unsigned int has_breaks : 1;
unsigned int gutted : 1;
unsigned int circulatory_spray : 1;
unsigned int locked_in_for_trading : 1; /*!< Locked in for trading (it's a projectile on the other set of flags, might be what the flying was) */
unsigned int slaughter : 1; /*!< marked for slaughter */
unsigned int underworld : 1; /*!< Underworld creature */
unsigned int resident : 1; /*!< Current resident */
unsigned int cleanup_4 : 1; /*!< Marked for special cleanup as unused load from unit block on disk */
unsigned int calculated_insulation : 1; /*!< Insulation from clothing calculated */
unsigned int visitor_uninvited : 1; /*!< Uninvited guest */
unsigned int visitor : 1; /*!< visitor */
unsigned int calculated_inventory : 1; /*!< Inventory order calculated */
unsigned int vision_good : 1; /*!< Vision -- have good part */
unsigned int vision_damaged : 1; /*!< Vision -- have damaged part */
unsigned int vision_missing : 1; /*!< Vision -- have missing part */
unsigned int breathing_good : 1; /*!< Breathing -- have good part */
unsigned int breathing_problem : 1; /*!< Breathing -- having a problem */
unsigned int roaming_wilderness_population_source : 1;
unsigned int roaming_wilderness_population_source_not_a_map_feature : 1;
} bits;
}; };
// FIXME: WTF IS THIS SHIT?
/* /*
struct t_labor struct t_labor
{ {
@ -255,13 +179,18 @@ namespace DFHack
} }
}; };
*/ */
/**
* \ingroup grp_creatures
*/
struct t_skill struct t_skill
{ {
uint32_t id; uint32_t id;
uint32_t rating; uint32_t rating;
uint32_t experience; uint32_t experience;
}; };
/**
* \ingroup grp_creatures
*/
struct t_job struct t_job
{ {
bool active; bool active;
@ -269,6 +198,9 @@ namespace DFHack
uint8_t jobType; uint8_t jobType;
uint32_t occupationPtr; uint32_t occupationPtr;
}; };
/**
* \ingroup grp_creatures
*/
struct t_like struct t_like
{ {
int16_t type; int16_t type;
@ -279,12 +211,15 @@ namespace DFHack
}; };
// FIXME: define in Memory.xml instead? // FIXME: THIS IS VERY, VERY BAD.
#define NUM_CREATURE_TRAITS 30 #define NUM_CREATURE_TRAITS 30
#define NUM_CREATURE_LABORS 102 #define NUM_CREATURE_LABORS 102
#define NUM_CREATURE_MENTAL_ATTRIBUTES 13 #define NUM_CREATURE_MENTAL_ATTRIBUTES 13
#define NUM_CREATURE_PHYSICAL_ATTRIBUTES 6 #define NUM_CREATURE_PHYSICAL_ATTRIBUTES 6
/**
* structure for holding a DF creature's soul
* \ingroup grp_creatures
*/
struct t_soul struct t_soul
{ {
uint8_t numSkills; uint8_t numSkills;
@ -310,7 +245,10 @@ namespace DFHack
}; };
#define MAX_COLORS 15 #define MAX_COLORS 15
/**
* structure for holding a DF creature
* \ingroup grp_creatures
*/
struct t_creature struct t_creature
{ {
uint32_t origin; uint32_t origin;
@ -358,7 +296,11 @@ namespace DFHack
}; };
class DFContextShared; class DFContextShared;
struct t_creature; /**
* The Creatures module - allows reading all non-vermin creatures and their properties
* \ingroup grp_modules
* \ingroup grp_creatures
*/
class DFHACK_EXPORT Creatures : public Module class DFHACK_EXPORT Creatures : public Module
{ {
public: public:

@ -1,16 +1,54 @@
#ifndef CL_MOD_GUI #ifndef CL_MOD_GUI
#define CL_MOD_GUI #define CL_MOD_GUI
/*
* Gui: Query the DF's GUI state
*/
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h" #include "dfhack/DFModule.h"
/**
* \defgroup grp_gui query DF's GUI state
* @ingroup grp_modules
*/
namespace DFHack namespace DFHack
{ {
class DFContextShared; class DFContextShared;
struct t_viewscreen; /**
* \ingroup grp_gui
*/
struct t_viewscreen
{
int32_t type;
//There is more info in these objects, but I don't know what it is yet
};
#define NUM_HOTKEYS 16
/**
* \ingroup grp_gui
*/
struct t_hotkey
{
char name[10];
int16_t mode;
int32_t x;
int32_t y;
int32_t z;
};
/**
* \ingroup grp_gui
*/
struct t_screen
{
uint8_t symbol;
uint8_t foreground;
uint8_t background;
uint8_t bright;
uint8_t gtile;
uint8_t grayscale;
};
/**
* The Gui module
* \ingroup grp_modules
* \ingroup grp_gui
*/
class DFHACK_EXPORT Gui: public Module class DFHACK_EXPORT Gui: public Module
{ {
public: public:
@ -19,11 +57,29 @@ namespace DFHack
~Gui(); ~Gui();
bool Start(); bool Start();
bool Finish(); bool Finish();
/*
* Cursor and window coords
*/
bool getViewCoords (int32_t &x, int32_t &y, int32_t &z);
bool setViewCoords (const int32_t x, const int32_t y, const int32_t z);
bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z);
bool setCursorCoords (const int32_t x, const int32_t y, const int32_t z);
/*
* Hotkeys (DF's zoom locations)
*/
bool ReadHotkeys(t_hotkey hotkeys[]);
/*
* Window size in tiles
*/
bool getWindowSize(int32_t & width, int32_t & height);
/*
* Screen tiles
*/
bool getScreenTiles(int32_t width, int32_t height, t_screen screen[]);
///true if paused, false if not
bool ReadPauseState();
///true if paused, false if not
void SetPauseState(bool paused);
/// read the DF menu view state (stock screen, unit screen, other screens /// read the DF menu view state (stock screen, unit screen, other screens
bool ReadViewScreen(t_viewscreen &); bool ReadViewScreen(t_viewscreen &);
/// read the DF menu state (designation menu ect) /// read the DF menu state (designation menu ect)
@ -33,6 +89,7 @@ namespace DFHack
struct Private; struct Private;
Private *d; Private *d;
}; };
typedef class Gui Position;
} }
#endif #endif

@ -8,12 +8,20 @@
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h" #include "dfhack/DFModule.h"
#include "Vegetation.h" #include "Vegetation.h"
/**
* \defgroup grp_maps Maps module and its types
* @ingroup grp_modules
*/
namespace DFHack namespace DFHack
{ {
/*************************************************************************** /***************************************************************************
T Y P E S T Y P E S
***************************************************************************/ ***************************************************************************/
/**
* \ingroup grp_maps
*/
enum e_feature enum e_feature
{ {
feature_Other, feature_Other,
@ -21,9 +29,16 @@ namespace DFHack
feature_Underworld, feature_Underworld,
feature_Hell_Temple feature_Hell_Temple
}; };
/**
extern DFHACK_EXPORT const char * sa_feature(int index); * Function for translating feature index to its name
* \ingroup grp_maps
*/
extern DFHACK_EXPORT const char * sa_feature(e_feature index);
/**
* Class for holding a world coordinate. Can do math with coordinates and can be used as an index for std::map
* \ingroup grp_maps
*/
class DFCoord class DFCoord
{ {
public: public:
@ -82,9 +97,15 @@ namespace DFHack
uint64_t comparate; uint64_t comparate;
}; };
}; };
/**
* \ingroup grp_maps
*/
typedef DFCoord planecoord; typedef DFCoord planecoord;
/**
* A local or global map feature
* \ingroup grp_maps
*/
struct t_feature struct t_feature
{ {
e_feature type; e_feature type;
@ -98,7 +119,10 @@ namespace DFHack
uint32_t origin; uint32_t origin;
}; };
/// mineral vein object /**
* mineral vein object - bitmap with a material type
* \ingroup grp_maps
*/
struct t_vein struct t_vein
{ {
uint32_t vtable; uint32_t vtable;
@ -112,7 +136,10 @@ namespace DFHack
uint32_t address_of; uint32_t address_of;
}; };
/// stores what tiles should appear when the ice melts /**
* stores what tiles should appear when the ice melts - bitmap of material types
* \ingroup grp_maps
*/
struct t_frozenliquidvein struct t_frozenliquidvein
{ {
uint32_t vtable; uint32_t vtable;
@ -122,8 +149,12 @@ namespace DFHack
uint32_t address_of; uint32_t address_of;
}; };
/// a 'spattervein' defines what coverings the individual map tiles have (snow, blood, etc) /**
/// @see PrintSplatterType in DFMiscUtils.h -- incomplete, but illustrative * a 'spattervein' defines what coverings the individual map tiles have (snow, blood, etc)
* bitmap of intensity with matrial type
* \ingroup grp_maps
* @see PrintSplatterType
*/
struct t_spattervein struct t_spattervein
{ {
uint32_t vtable; uint32_t vtable;
@ -139,7 +170,11 @@ namespace DFHack
/// this is NOT part of the DF vein, but an address of the vein as seen by DFhack. /// this is NOT part of the DF vein, but an address of the vein as seen by DFhack.
uint32_t address_of; uint32_t address_of;
}; };
/**
* a 'grass vein' defines the grass coverage of a map block
* bitmap of density (max = 100) with plant material type
* \ingroup grp_maps
*/
struct t_grassvein struct t_grassvein
{ {
uint32_t vtable; uint32_t vtable;
@ -150,7 +185,10 @@ namespace DFHack
/// this is NOT part of the DF vein, but an address of the vein as seen by DFhack. /// this is NOT part of the DF vein, but an address of the vein as seen by DFhack.
uint32_t address_of; uint32_t address_of;
}; };
/**
* defines the world constructions present. The material member is a mystery.
* \ingroup grp_maps
*/
struct t_worldconstruction struct t_worldconstruction
{ {
uint32_t vtable; uint32_t vtable;
@ -162,6 +200,9 @@ namespace DFHack
uint32_t address_of; uint32_t address_of;
}; };
/**
* \ingroup grp_maps
*/
enum BiomeOffset enum BiomeOffset
{ {
eNorthWest, eNorthWest,
@ -176,6 +217,9 @@ namespace DFHack
eBiomeCount eBiomeCount
}; };
/**
* \ingroup grp_maps
*/
enum e_traffic enum e_traffic
{ {
traffic_normal, traffic_normal,
@ -184,7 +228,10 @@ namespace DFHack
traffic_restricted traffic_restricted
}; };
/// type of a designation for a tile /**
* type of a designation for a tile
* \ingroup grp_maps
*/
enum e_designation enum e_designation
{ {
/// no designation /// no designation
@ -205,12 +252,20 @@ namespace DFHack
designation_7 designation_7
}; };
/**
* type of liquid in a tile
* \ingroup grp_maps
*/
enum e_liquidtype enum e_liquidtype
{ {
liquid_water, liquid_water,
liquid_magma liquid_magma
}; };
/**
* designation bit field
* \ingroup grp_maps
*/
struct naked_designation struct naked_designation
{ {
unsigned int flow_size : 3; // how much liquid is here? unsigned int flow_size : 3; // how much liquid is here?
@ -254,16 +309,21 @@ namespace DFHack
unsigned int water_salt : 1; unsigned int water_salt : 1;
// e_liquidcharacter liquid_character : 2; // e_liquidcharacter liquid_character : 2;
}; };
/**
* designation bit field wrapper
* \ingroup grp_maps
*/
union t_designation union t_designation
{ {
uint32_t whole; uint32_t whole;
naked_designation bits; naked_designation bits;
}; };
// occupancy flags (rat,dwarf,horse,built wall,not build wall,etc) /**
//FIXME: THIS IS NOT VALID FOR 31.xx versions!!!! * occupancy flags (rat,dwarf,horse,built wall,not build wall,etc)
struct naked_occupancy * \ingroup grp_maps
*/
struct naked_occupancy //FIXME: THIS IS NOT VALID FOR 31.xx versions!!!!
{ {
// building type... should be an enum? // building type... should be an enum?
// 7 = door // 7 = door
@ -303,28 +363,20 @@ namespace DFHack
unsigned int snow : 1; unsigned int snow : 1;
*/ */
}; };
/**
struct naked_occupancy_grouped * occupancy flags (rat,dwarf,horse,built wall,not build wall,etc) wrapper
{ * \ingroup grp_maps
unsigned int building : 3; */
/// the tile contains a standing? creature
unsigned int unit : 1;
/// the tile contains a prone creature
unsigned int unit_grounded : 1;
/// the tile contains an item
unsigned int item : 1;
/// changed
unsigned int unknown : 26;
};
union t_occupancy union t_occupancy
{ {
uint32_t whole; uint32_t whole;
naked_occupancy bits; naked_occupancy bits;
naked_occupancy_grouped unibits;
}; };
// map block flags /**
* map block flags
* \ingroup grp_maps
*/
struct naked_blockflags struct naked_blockflags
{ {
/// designated for jobs (digging and stuff like that) /// designated for jobs (digging and stuff like that)
@ -339,19 +391,50 @@ namespace DFHack
// there's a possibility that this flags field is shorter than 32 bits // there's a possibility that this flags field is shorter than 32 bits
}; };
/**
* map block flags wrapper
* \ingroup grp_maps
*/
union t_blockflags union t_blockflags
{ {
uint32_t whole; uint32_t whole;
naked_blockflags bits; naked_blockflags bits;
}; };
/**
* 16x16 array of tile types
* \ingroup grp_maps
*/
typedef int16_t tiletypes40d [16][16]; typedef int16_t tiletypes40d [16][16];
typedef int16_t t_blockmaterials [16][16]; ///< used for squashed block materials /**
* 16x16 array used for squashed block materials
* \ingroup grp_maps
*/
typedef int16_t t_blockmaterials [16][16];
/**
* 16x16 array of designation flags
* \ingroup grp_maps
*/
typedef DFHack::t_designation designations40d [16][16]; typedef DFHack::t_designation designations40d [16][16];
/**
* 16x16 array of occupancy flags
* \ingroup grp_maps
*/
typedef DFHack::t_occupancy occupancies40d [16][16]; typedef DFHack::t_occupancy occupancies40d [16][16];
/**
* array of 16 biome indexes valid for the block
* \ingroup grp_maps
*/
typedef uint8_t biome_indices40d [16]; typedef uint8_t biome_indices40d [16];
/**
* 16x16 array of temperatures
* \ingroup grp_maps
*/
typedef uint16_t t_temperatures [16][16]; typedef uint16_t t_temperatures [16][16];
/**
* structure for holding whole blocks
* \ingroup grp_maps
*/
typedef struct typedef struct
{ {
/// type of the tiles /// type of the tiles
@ -376,7 +459,11 @@ namespace DFHack
***************************************************************************/ ***************************************************************************/
#ifndef BUILD_SHM #ifndef BUILD_SHM
class DFContextShared; class DFContextShared;
struct t_viewscreen; /**
* The Maps module
* \ingroup grp_modules
* \ingroup grp_maps
*/
class DFHACK_EXPORT Maps : public Module class DFHACK_EXPORT Maps : public Module
{ {
public: public:

@ -1,14 +1,17 @@
#ifndef CL_MOD_MATERIALS #ifndef CL_MOD_MATERIALS
#define CL_MOD_MATERIALS #define CL_MOD_MATERIALS
/* /**
* Materials * \defgroup grp_materials Materials module - used for reading raws mostly
* @ingroup grp_modules
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h" #include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
class DFContextShared; class DFContextShared;
/**
* \ingroup grp_materials
*/
struct t_matgloss struct t_matgloss
{ {
char id[128]; //the id in the raws char id[128]; //the id in the raws
@ -17,7 +20,9 @@ namespace DFHack
uint8_t bright; uint8_t bright;
char name[128]; //this is the name displayed ingame char name[128]; //this is the name displayed ingame
}; };
/**
* \ingroup grp_materials
*/
struct t_descriptor_color struct t_descriptor_color
{ {
char id[128]; // id in the raws char id[128]; // id in the raws
@ -26,7 +31,9 @@ namespace DFHack
float b; float b;
char name[128]; //displayed name char name[128]; //displayed name
}; };
/**
* \ingroup grp_materials
*/
struct t_matglossPlant struct t_matglossPlant
{ {
char id[128]; //the id in the raws char id[128]; //the id in the raws
@ -38,7 +45,9 @@ namespace DFHack
char food_name[128]; char food_name[128];
char extract_name[128]; char extract_name[128];
}; };
/**
* \ingroup grp_materials
*/
struct t_bodypart struct t_bodypart
{ {
char id[128]; char id[128];
@ -46,7 +55,9 @@ namespace DFHack
char single[128]; char single[128];
char plural[128]; char plural[128];
}; };
/**
* \ingroup grp_materials
*/
struct t_colormodifier struct t_colormodifier
{ {
char part[128]; char part[128];
@ -54,7 +65,9 @@ namespace DFHack
uint32_t startdate; /* in days */ uint32_t startdate; /* in days */
uint32_t enddate; /* in days */ uint32_t enddate; /* in days */
}; };
/**
* \ingroup grp_materials
*/
struct t_creaturecaste struct t_creaturecaste
{ {
char rawname[128]; char rawname[128];
@ -82,17 +95,23 @@ namespace DFHack
t_attrib musicality; t_attrib musicality;
t_attrib kinesthetic_sense; t_attrib kinesthetic_sense;
}; };
/**
* \ingroup grp_materials
*/
struct t_matglossOther struct t_matglossOther
{ {
char rawname[128]; char rawname[128];
}; };
/**
* \ingroup grp_materials
*/
struct t_creatureextract struct t_creatureextract
{ {
char rawname[128]; char rawname[128];
}; };
// this doesn't transfer well across the shm gap... /**
* \ingroup grp_materials
*/
struct t_creaturetype struct t_creaturetype
{ {
char rawname[128]; char rawname[128];
@ -107,7 +126,10 @@ namespace DFHack
} tilecolor; } tilecolor;
}; };
// this structure describes what are things made of in the DF world /**
* this structure describes what are things made of in the DF world
* \ingroup grp_materials
*/
struct t_material struct t_material
{ {
int16_t itemType; int16_t itemType;
@ -116,7 +138,11 @@ namespace DFHack
int32_t index; int32_t index;
uint32_t flags; uint32_t flags;
}; };
/**
* The Materials module
* \ingroup grp_modules
* \ingroup grp_materials
*/
class DFHACK_EXPORT Materials : public Module class DFHACK_EXPORT Materials : public Module
{ {
public: public:

@ -1,67 +1,4 @@
#ifndef CL_MOD_POSITION #ifndef CL_MOD_POSITION
#define CL_MOD_POSITION #define CL_MOD_POSITION
/* // blorp
* View position and size and cursor position
*/
#include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
namespace DFHack
{
#define NUM_HOTKEYS 16
struct t_hotkey
{
char name[10];
int16_t mode;
int32_t x;
int32_t y;
int32_t z;
};
struct t_screen
{
uint8_t symbol;
uint8_t foreground;
uint8_t background;
uint8_t bright;
uint8_t gtile;
uint8_t grayscale;
};
class DFContextShared;
class DFHACK_EXPORT Position : public Module
{
public:
Position(DFContextShared * d);
~Position();
bool Finish(){return true;};
/*
* Cursor and window coords
*/
bool getViewCoords (int32_t &x, int32_t &y, int32_t &z);
bool setViewCoords (const int32_t x, const int32_t y, const int32_t z);
bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z);
bool setCursorCoords (const int32_t x, const int32_t y, const int32_t z);
/*
* Hotkeys (DF's zoom locations)
*/
bool ReadHotkeys(t_hotkey hotkeys[]);
/*
* Window size in tiles
*/
bool getWindowSize(int32_t & width, int32_t & height);
/*
* Screen tiles
*/
bool getScreenTiles(int32_t width, int32_t height, t_screen screen[]);
private:
struct Private;
Private *d;
};
}
#endif #endif

@ -1,20 +1,32 @@
#ifndef CL_MOD_TRANSLATION #ifndef CL_MOD_TRANSLATION
#define CL_MOD_TRANSLATION #define CL_MOD_TRANSLATION
/* /**
* DF translation tables and name translation * \defgroup grp_translation Translation: DF word tables and name translation/reading
*/ * @ingroup grp_modules
*/
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h" #include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
class DFContextShared; class DFContextShared;
/**
* \ingroup grp_translation
*/
typedef std::vector< std::vector<std::string> > DFDict; typedef std::vector< std::vector<std::string> > DFDict;
/**
* \ingroup grp_translation
*/
typedef struct typedef struct
{ {
DFDict translations; DFDict translations;
DFDict foreign_languages; DFDict foreign_languages;
} Dicts; } Dicts;
/**
* The Tanslation module
* \ingroup grp_translation
* \ingroup grp_maps
*/
class DFHACK_EXPORT Translation : public Module class DFHACK_EXPORT Translation : public Module
{ {
public: public:

@ -1,21 +1,26 @@
#ifndef CL_MOD_VEGETATION #ifndef CL_MOD_VEGETATION
#define CL_MOD_VEGETATION #define CL_MOD_VEGETATION
/* /**
* DF vegetation - stuff that grows and gets cut down or trampled by dwarves * \defgroup grp_vegetation Vegetation : stuff that grows and gets cut down or trampled by dwarves
*/ * @ingroup grp_modules
*/
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h" #include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
/*
types /**
0: sapling?, dead sapling?, grown maple tree * \ingroup grp_vegetation
1: willow sapling? */
2: shrub
3: shrub near water!
*/
struct t_tree struct t_tree
{ {
/**
0: sapling?, dead sapling?, grown maple tree
1: willow sapling?
2: shrub
3: shrub near water!
*/
uint16_t type; // +0x6C uint16_t type; // +0x6C
uint16_t material; // +0x6E uint16_t material; // +0x6E
uint16_t x; // +0x70 uint16_t x; // +0x70
@ -29,6 +34,11 @@ namespace DFHack
}; };
class DFContextShared; class DFContextShared;
/**
* The Vegetation module
* \ingroup grp_vegetation
* \ingroup grp_modules
*/
class DFHACK_EXPORT Vegetation : public Module class DFHACK_EXPORT Vegetation : public Module
{ {
public: public:

@ -25,15 +25,23 @@ distribution.
#ifndef KEYS_H_INCLUDED #ifndef KEYS_H_INCLUDED
#define KEYS_H_INCLUDED #define KEYS_H_INCLUDED
/**
* \defgroup grp_windowio WindowIO: Send events to DF's window
* @ingroup grp_modules
*/
#include "../DFPragma.h" #include "../DFPragma.h"
#include "../DFExport.h" #include "../DFExport.h"
#include "../DFModule.h" #include "../DFModule.h"
namespace DFHack namespace DFHack
{ {
class Process; class Process;
/**
* enum of all possible special keys
* \ingroup grp_windowio
*/
enum t_special enum t_special
{ {
ENTER, ENTER,
@ -89,6 +97,11 @@ enum t_special
NUM_SPECIALS NUM_SPECIALS
}; };
class DFContextShared; class DFContextShared;
/**
* The WindowIO module
* \ingroup grp_windowio
* \ingroup grp_modules
*/
class DFHACK_EXPORT WindowIO : public Module class DFHACK_EXPORT WindowIO : public Module
{ {
class Private; class Private;

@ -1,21 +1,29 @@
#ifndef CL_MOD_WORLD #ifndef CL_MOD_WORLD
#define CL_MOD_WORLD #define CL_MOD_WORLD
/* /**
* World: all kind of stuff related to the current world state * \defgroup grp_world World: all kind of stuff related to the current world state
*/ * @ingroup grp_modules
*/
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h" #include "dfhack/DFModule.h"
#include <ostream> #include <ostream>
namespace DFHack namespace DFHack
{ {
/**
* \ingroup grp_world
*/
enum WeatherType enum WeatherType
{ {
CLEAR, CLEAR,
RAINING, RAINING,
SNOWING SNOWING
}; };
/**
* \ingroup grp_world
*/
enum ControlMode enum ControlMode
{ {
CM_Managing = 0, CM_Managing = 0,
@ -24,6 +32,9 @@ namespace DFHack
CM_Menu = 3, CM_Menu = 3,
CM_MAX = 3 CM_MAX = 3
}; };
/**
* \ingroup grp_world
*/
enum GameMode enum GameMode
{ {
GM_Fort = 0, GM_Fort = 0,
@ -31,17 +42,25 @@ namespace DFHack
GM_Legends = 2, GM_Legends = 2,
GM_Menu = 3, GM_Menu = 3,
GM_Arena = 4, GM_Arena = 4,
GM_Arena_Assumed = 5, GM_Arena_Assumed = 5,
GM_Kittens = 6, GM_Kittens = 6,
GM_Worldgen = 7, GM_Worldgen = 7,
GM_MAX = 7, GM_MAX = 7,
}; };
/**
* \ingroup grp_world
*/
struct t_gamemodes struct t_gamemodes
{ {
ControlMode control_mode; ControlMode control_mode;
GameMode game_mode; GameMode game_mode;
}; };
class DFContextShared; class DFContextShared;
/**
* The World module
* \ingroup grp_modules
* \ingroup grp_world
*/
class DFHACK_EXPORT World : public Module class DFHACK_EXPORT World : public Module
{ {
public: public:
@ -51,6 +70,11 @@ namespace DFHack
bool Start(); bool Start();
bool Finish(); bool Finish();
///true if paused, false if not
bool ReadPauseState();
///true if paused, false if not
void SetPauseState(bool paused);
uint32_t ReadCurrentTick(); uint32_t ReadCurrentTick();
uint32_t ReadCurrentYear(); uint32_t ReadCurrentYear();
uint32_t ReadCurrentMonth(); uint32_t ReadCurrentMonth();

@ -28,6 +28,7 @@ distribution.
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/VersionInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/DFError.h"
#include "ModuleFactory.h" #include "ModuleFactory.h"
using namespace DFHack; using namespace DFHack;
@ -41,15 +42,31 @@ struct Gui::Private
{ {
Private() Private()
{ {
Started = PauseInited = ViewScreeInited = MenuStateInited = false; Started = ViewScreeInited = MenuStateInited = false;
StartedHotkeys = StartedScreen = false;
} }
bool Started;
uint32_t pause_state_offset;
bool PauseInited;
uint32_t view_screen_offset;
bool ViewScreeInited; bool ViewScreeInited;
uint32_t current_menu_state_offset; uint32_t view_screen_offset;
bool MenuStateInited; bool MenuStateInited;
uint32_t current_menu_state_offset;
bool Started;
uint32_t window_x_offset;
uint32_t window_y_offset;
uint32_t window_z_offset;
uint32_t cursor_xyz_offset;
uint32_t window_dims_offset;
bool StartedHotkeys;
uint32_t hotkey_start;
uint32_t hotkey_mode_offset;
uint32_t hotkey_xyz_offset;
uint32_t hotkey_size;
bool StartedScreen;
uint32_t screen_tiles_ptr_offset;
DFContextShared *d; DFContextShared *d;
Process * owner; Process * owner;
}; };
@ -60,7 +77,8 @@ Gui::Gui(DFContextShared * _d)
d = new Private; d = new Private;
d->d = _d; d->d = _d;
d->owner = _d->p; d->owner = _d->p;
OffsetGroup * OG_Gui = d->d->offset_descriptor->getGroup("GUI"); VersionInfo * mem = d->d->offset_descriptor;
OffsetGroup * OG_Gui = mem->getGroup("GUI");
try try
{ {
d->current_menu_state_offset = OG_Gui->getAddress("current_menu_state"); d->current_menu_state_offset = OG_Gui->getAddress("current_menu_state");
@ -69,17 +87,38 @@ Gui::Gui(DFContextShared * _d)
catch(exception &){}; catch(exception &){};
try try
{ {
d->pause_state_offset = OG_Gui->getAddress ("pause_state"); d->view_screen_offset = OG_Gui->getAddress ("view_screen");
d->PauseInited = true; d->ViewScreeInited = true;
} }
catch(exception &){}; catch(exception &){};
OffsetGroup * OG_Position;
try try
{ {
d->view_screen_offset = OG_Gui->getAddress ("view_screen"); OG_Position = mem->getGroup("Position");
d->ViewScreeInited = true; d->window_x_offset = OG_Position->getAddress ("window_x");
d->window_y_offset = OG_Position->getAddress ("window_y");
d->window_z_offset = OG_Position->getAddress ("window_z");
d->cursor_xyz_offset = OG_Position->getAddress ("cursor_xyz");
d->window_dims_offset = OG_Position->getAddress ("window_dims");
d->Started = true;
} }
catch(exception &){}; catch(Error::All &){};
d->Started = true; try
{
OffsetGroup * OG_Hotkeys = mem->getGroup("Hotkeys");
d->hotkey_start = OG_Hotkeys->getAddress("start");
d->hotkey_mode_offset = OG_Hotkeys->getOffset ("mode");
d->hotkey_xyz_offset = OG_Hotkeys->getOffset("coords");
d->hotkey_size = OG_Hotkeys->getHexValue("size");
d->StartedHotkeys = true;
}
catch(Error::All &){};
try
{
d->screen_tiles_ptr_offset = OG_Position->getAddress ("screen_tiles_pointer");
d->StartedScreen = true;
}
catch(Error::All &){};
} }
Gui::~Gui() Gui::~Gui()
@ -97,21 +136,6 @@ bool Gui::Finish()
return true; return true;
} }
bool Gui::ReadPauseState()
{
if(!d->PauseInited) return false;
uint32_t pauseState = d->owner->readDWord (d->pause_state_offset);
return pauseState & 1;
}
void Gui::SetPauseState(bool paused)
{
if(!d->PauseInited) return;
cout << "pause set" << endl;
d->owner->writeDWord (d->pause_state_offset, paused);
}
uint32_t Gui::ReadMenuState() uint32_t Gui::ReadMenuState()
{ {
if(d->MenuStateInited) if(d->MenuStateInited)
@ -135,3 +159,108 @@ bool Gui::ReadViewScreen (t_viewscreen &screen)
} }
return d->d->offset_descriptor->resolveObjectToClassID (last, screen.type); return d->d->offset_descriptor->resolveObjectToClassID (last, screen.type);
} }
bool Gui::ReadHotkeys(t_hotkey hotkeys[])
{
if (!d->StartedHotkeys)
{
return false;
}
uint32_t currHotkey = d->hotkey_start;
Process * p = d->owner;
for(uint32_t i = 0 ; i < NUM_HOTKEYS ;i++)
{
p->readSTLString(currHotkey,hotkeys[i].name,10);
hotkeys[i].mode = p->readWord(currHotkey+d->hotkey_mode_offset);
p->read (currHotkey + d->hotkey_xyz_offset, 3*sizeof (int32_t), (uint8_t *) &hotkeys[i].x);
currHotkey+=d->hotkey_size;
}
return true;
}
bool Gui::getViewCoords (int32_t &x, int32_t &y, int32_t &z)
{
if (!d->Started) return false;
Process * p = d->owner;
p->readDWord (d->window_x_offset, (uint32_t &) x);
p->readDWord (d->window_y_offset, (uint32_t &) y);
p->readDWord (d->window_z_offset, (uint32_t &) z);
return true;
}
//FIXME: confine writing of coords to map bounds?
bool Gui::setViewCoords (const int32_t x, const int32_t y, const int32_t z)
{
if (!d->Started)
{
return false;
}
Process * p = d->owner;
p->writeDWord (d->window_x_offset, (uint32_t) x);
p->writeDWord (d->window_y_offset, (uint32_t) y);
p->writeDWord (d->window_z_offset, (uint32_t) z);
return true;
}
bool Gui::getCursorCoords (int32_t &x, int32_t &y, int32_t &z)
{
if(!d->Started) return false;
int32_t coords[3];
d->owner->read (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords);
x = coords[0];
y = coords[1];
z = coords[2];
if (x == -30000) return false;
return true;
}
//FIXME: confine writing of coords to map bounds?
bool Gui::setCursorCoords (const int32_t x, const int32_t y, const int32_t z)
{
if (!d->Started) return false;
int32_t coords[3] = {x, y, z};
d->owner->write (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords);
return true;
}
bool Gui::getWindowSize (int32_t &width, int32_t &height)
{
if(!d->Started) return false;
int32_t coords[2];
d->owner->read (d->window_dims_offset, 2*sizeof (int32_t), (uint8_t *) coords);
width = coords[0];
height = coords[1];
return true;
}
bool Gui::getScreenTiles (int32_t width, int32_t height, t_screen screen[])
{
if(!d->StartedScreen) return false;
uint32_t screen_addr = d->owner->readDWord(d->screen_tiles_ptr_offset);
uint8_t* tiles = new uint8_t[width*height*4/* + 80 + width*height*4*/];
d->owner->read (screen_addr, (width*height*4/* + 80 + width*height*4*/), (uint8_t *) tiles);
for(int32_t iy=0; iy<height; iy++)
{
for(int32_t ix=0; ix<width; ix++)
{
screen[ix + iy*width].symbol = tiles[(iy + ix*height)*4 +0];
screen[ix + iy*width].foreground = tiles[(iy + ix*height)*4 +1];
screen[ix + iy*width].background = tiles[(iy + ix*height)*4 +2];
screen[ix + iy*width].bright = tiles[(iy + ix*height)*4 +3];
//screen[ix + iy*width].gtile = tiles[width*height*4 + 80 + iy + ix*height +0];
//screen[ix + iy*width].grayscale = tiles[width*height*4 + 80 + iy + ix*height +1];
}
}
delete [] tiles;
return true;
}

@ -48,17 +48,17 @@ Module* DFHack::createMaps(DFContextShared * d)
return new Maps(d); return new Maps(d);
} }
const char * DFHack::sa_feature(int index) const char * DFHack::sa_feature(e_feature index)
{ {
switch(index) switch(index)
{ {
case 0: case feature_Other:
return "Other"; return "Other";
case 1: case feature_Adamantine_Tube:
return "Adamantine Tube"; return "Adamantine Tube";
case 2: case feature_Underworld:
return "Underworld"; return "Underworld";
case 3: case feature_Hell_Temple:
return "Hell Temple"; return "Hell Temple";
default: default:
return "Unknown/Error"; return "Unknown/Error";
@ -1039,7 +1039,7 @@ bool Maps::ReadVegetation(uint32_t x, uint32_t y, uint32_t z, std::vector<t_tree
Server::Maps::maps_offsets & off = d->offsets; Server::Maps::maps_offsets & off = d->offsets;
DfVector<uint32_t> vegptrs(d->owner, addr + off.vegvector); DfVector<uint32_t> vegptrs(d->owner, addr + off.vegvector);
for(int i = 0; i < vegptrs.size(); i++) for(size_t i = 0; i < vegptrs.size(); i++)
{ {
d->owner->read (vegptrs[i] + off.tree_desc_offset, sizeof (t_tree), (uint8_t *) &shrubbery); d->owner->read (vegptrs[i] + off.tree_desc_offset, sizeof (t_tree), (uint8_t *) &shrubbery);
shrubbery.address = vegptrs[i]; shrubbery.address = vegptrs[i];

@ -1,211 +1,2 @@
/* // blorp
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
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 "Internal.h"
#include "ContextShared.h"
#include "dfhack/modules/Position.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFError.h"
#include "ModuleFactory.h"
using namespace DFHack;
Module* DFHack::createPosition(DFContextShared * d)
{
return new Position(d);
}
struct Position::Private
{
uint32_t window_x_offset;
uint32_t window_y_offset;
uint32_t window_z_offset;
uint32_t cursor_xyz_offset;
uint32_t window_dims_offset;
uint32_t hotkey_start;
uint32_t hotkey_mode_offset;
uint32_t hotkey_xyz_offset;
uint32_t hotkey_size;
uint32_t screen_tiles_ptr_offset;
DFContextShared *d;
Process * owner;
bool Inited;
bool Started;
bool StartedHotkeys;
bool StartedScreen;
};
Position::Position(DFContextShared * d_)
{
d = new Private;
d->d = d_;
d->owner = d_->p;
d->Inited = true;
d->StartedHotkeys = d->Started = d->StartedScreen = false;
OffsetGroup * OG_Position;
VersionInfo * mem = d->d->offset_descriptor;
// this is how to do feature detection properly
try
{
OG_Position = mem->getGroup("Position");
d->window_x_offset = OG_Position->getAddress ("window_x");
d->window_y_offset = OG_Position->getAddress ("window_y");
d->window_z_offset = OG_Position->getAddress ("window_z");
d->cursor_xyz_offset = OG_Position->getAddress ("cursor_xyz");
d->window_dims_offset = OG_Position->getAddress ("window_dims");
d->Started = true;
}
catch(Error::All &){};
try
{
OffsetGroup * OG_Hotkeys = mem->getGroup("Hotkeys");
d->hotkey_start = OG_Hotkeys->getAddress("start");
d->hotkey_mode_offset = OG_Hotkeys->getOffset ("mode");
d->hotkey_xyz_offset = OG_Hotkeys->getOffset("coords");
d->hotkey_size = OG_Hotkeys->getHexValue("size");
d->StartedHotkeys = true;
}
catch(Error::All &){};
try
{
d->screen_tiles_ptr_offset = OG_Position->getAddress ("screen_tiles_pointer");
d->StartedScreen = true;
}
catch(Error::All &){};
}
Position::~Position()
{
delete d;
}
bool Position::ReadHotkeys(t_hotkey hotkeys[])
{
if (!d->StartedHotkeys)
{
return false;
}
uint32_t currHotkey = d->hotkey_start;
Process * p = d->owner;
for(uint32_t i = 0 ; i < NUM_HOTKEYS ;i++)
{
p->readSTLString(currHotkey,hotkeys[i].name,10);
hotkeys[i].mode = p->readWord(currHotkey+d->hotkey_mode_offset);
p->read (currHotkey + d->hotkey_xyz_offset, 3*sizeof (int32_t), (uint8_t *) &hotkeys[i].x);
currHotkey+=d->hotkey_size;
}
return true;
}
bool Position::getViewCoords (int32_t &x, int32_t &y, int32_t &z)
{
if (!d->Inited) return false;
Process * p = d->owner;
p->readDWord (d->window_x_offset, (uint32_t &) x);
p->readDWord (d->window_y_offset, (uint32_t &) y);
p->readDWord (d->window_z_offset, (uint32_t &) z);
return true;
}
//FIXME: confine writing of coords to map bounds?
bool Position::setViewCoords (const int32_t x, const int32_t y, const int32_t z)
{
if (!d->Inited)
{
return false;
}
Process * p = d->owner;
p->writeDWord (d->window_x_offset, (uint32_t) x);
p->writeDWord (d->window_y_offset, (uint32_t) y);
p->writeDWord (d->window_z_offset, (uint32_t) z);
return true;
}
bool Position::getCursorCoords (int32_t &x, int32_t &y, int32_t &z)
{
if(!d->Inited) return false;
int32_t coords[3];
d->owner->read (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords);
x = coords[0];
y = coords[1];
z = coords[2];
if (x == -30000) return false;
return true;
}
//FIXME: confine writing of coords to map bounds?
bool Position::setCursorCoords (const int32_t x, const int32_t y, const int32_t z)
{
if (!d->Inited) return false;
int32_t coords[3] = {x, y, z};
d->owner->write (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords);
return true;
}
bool Position::getWindowSize (int32_t &width, int32_t &height)
{
if(!d->Inited) return false;
int32_t coords[2];
d->owner->read (d->window_dims_offset, 2*sizeof (int32_t), (uint8_t *) coords);
width = coords[0];
height = coords[1];
return true;
}
bool Position::getScreenTiles (int32_t width, int32_t height, t_screen screen[])
{
if(!d->Inited) return false;
if(!d->StartedScreen) return false;
uint32_t screen_addr = d->owner->readDWord(d->screen_tiles_ptr_offset);
uint8_t* tiles = new uint8_t[width*height*4/* + 80 + width*height*4*/];
d->owner->read (screen_addr, (width*height*4/* + 80 + width*height*4*/), (uint8_t *) tiles);
for(int32_t iy=0; iy<height; iy++)
{
for(int32_t ix=0; ix<width; ix++)
{
screen[ix + iy*width].symbol = tiles[(iy + ix*height)*4 +0];
screen[ix + iy*width].foreground = tiles[(iy + ix*height)*4 +1];
screen[ix + iy*width].background = tiles[(iy + ix*height)*4 +2];
screen[ix + iy*width].bright = tiles[(iy + ix*height)*4 +3];
//screen[ix + iy*width].gtile = tiles[width*height*4 + 80 + iy + ix*height +0];
//screen[ix + iy*width].grayscale = tiles[width*height*4 + 80 + iy + ix*height +1];
}
}
delete [] tiles;
return true;
}

@ -22,18 +22,6 @@ must not be misrepresented as being the original software.
distribution. distribution.
*/ */
/*
FIXME: Japa said that he had to do this with the time stuff he got from here
Investigate.
currentYear = Wold->ReadCurrentYear();
currentTick = Wold->ReadCurrentTick();
currentMonth = (currentTick+9)/33600;
currentDay = ((currentTick+9)%33600)/1200;
currentHour = ((currentTick+9)-(((currentMonth*28)+currentDay)*1200))/50;
currentTickRel = (currentTick+9)-(((((currentMonth*28)+currentDay)*24)+currentHour)*50);
*/
#include "Internal.h" #include "Internal.h"
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/modules/World.h" #include "dfhack/modules/World.h"
@ -52,13 +40,23 @@ Module* DFHack::createWorld(DFContextShared * d)
struct World::Private struct World::Private
{ {
Private()
{
Inited = StartedTime = StartedWeather = StartedMode = PauseInited = false;
}
bool Inited; bool Inited;
bool PauseInited;
uint32_t pause_state_offset;
bool StartedTime; bool StartedTime;
bool StartedWeather;
bool StartedMode;
uint32_t year_offset; uint32_t year_offset;
uint32_t tick_offset; uint32_t tick_offset;
bool StartedWeather;
uint32_t weather_offset; uint32_t weather_offset;
bool StartedMode;
uint32_t gamemode_offset; uint32_t gamemode_offset;
uint32_t controlmode_offset; uint32_t controlmode_offset;
uint32_t controlmodecopy_offset; uint32_t controlmodecopy_offset;
@ -72,7 +70,6 @@ World::World(DFContextShared * _d)
d = new Private; d = new Private;
d->d = _d; d->d = _d;
d->owner = _d->p; d->owner = _d->p;
d->Inited = d->StartedTime = d->StartedWeather = d->StartedMode = false;
OffsetGroup * OG_World = d->d->offset_descriptor->getGroup("World"); OffsetGroup * OG_World = d->d->offset_descriptor->getGroup("World");
try try
@ -82,6 +79,13 @@ World::World(DFContextShared * _d)
d->StartedTime = true; d->StartedTime = true;
} }
catch(Error::All &){}; catch(Error::All &){};
OffsetGroup * OG_Gui = d->d->offset_descriptor->getGroup("GUI"); // FIXME: legacy
try
{
d->pause_state_offset = OG_Gui->getAddress ("pause_state");
d->PauseInited = true;
}
catch(exception &){};
try try
{ {
d->weather_offset = OG_World->getAddress( "current_weather" ); d->weather_offset = OG_World->getAddress( "current_weather" );
@ -114,6 +118,20 @@ bool World::Finish()
return true; return true;
} }
bool World::ReadPauseState()
{
if(!d->PauseInited) return false;
uint32_t pauseState = d->owner->readDWord (d->pause_state_offset);
return pauseState & 1;
}
void World::SetPauseState(bool paused)
{
if(!d->PauseInited) return;
d->owner->writeDWord (d->pause_state_offset, paused);
}
uint32_t World::ReadCurrentYear() uint32_t World::ReadCurrentYear()
{ {
if(d->Inited && d->StartedTime) if(d->Inited && d->StartedTime)
@ -150,6 +168,18 @@ bool World::WriteGameMode(const t_gamemodes & wr)
return false; return false;
} }
/*
FIXME: Japa said that he had to do this with the time stuff he got from here
Investigate.
currentYear = Wold->ReadCurrentYear();
currentTick = Wold->ReadCurrentTick();
currentMonth = (currentTick+9)/33600;
currentDay = ((currentTick+9)%33600)/1200;
currentHour = ((currentTick+9)-(((currentMonth*28)+currentDay)*1200))/50;
currentTickRel = (currentTick+9)-(((((currentMonth*28)+currentDay)*24)+currentHour)*50);
*/
// FIX'D according to this: // FIX'D according to this:
/* /*
World::ReadCurrentMonth and World::ReadCurrentDay World::ReadCurrentMonth and World::ReadCurrentDay
@ -176,13 +206,7 @@ uint8_t World::ReadCurrentWeather()
return(d->owner->readByte(d->weather_offset + 12)); return(d->owner->readByte(d->weather_offset + 12));
return 0; return 0;
} }
/*
void World::SetCurrentWeather(uint8_t weather)
{
if (d->Inited && d->StartedWeather)
d->owner->writeByte(d->weather_offset,weather);
}
*/
void World::SetCurrentWeather(uint8_t weather) void World::SetCurrentWeather(uint8_t weather)
{ {
if (d->Inited && d->StartedWeather) if (d->Inited && d->StartedWeather)

@ -35,7 +35,6 @@ namespace DFHack
class Creatures; class Creatures;
class Maps; class Maps;
class Position;
class Gui; class Gui;
class World; class World;
class Materials; class Materials;
@ -76,7 +75,7 @@ namespace DFHack
{ {
Creatures * pCreatures; Creatures * pCreatures;
Maps * pMaps; Maps * pMaps;
Position * pPosition; Gui * pPosition; // blerp
Gui * pGui; Gui * pGui;
World * pWorld; World * pWorld;
Materials * pMaterials; Materials * pMaterials;