2011-06-16 15:53:39 -06:00
|
|
|
/*
|
|
|
|
https://github.com/peterix/dfhack
|
2012-09-29 20:03:37 -06:00
|
|
|
Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com)
|
2011-06-16 15:53:39 -06:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2011-04-10 05:12:28 -06:00
|
|
|
#pragma once
|
2010-05-12 07:27:51 -06:00
|
|
|
#ifndef CL_MOD_WORLD
|
|
|
|
#define CL_MOD_WORLD
|
|
|
|
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* \defgroup grp_world World: all kind of stuff related to the current world state
|
|
|
|
* @ingroup grp_modules
|
|
|
|
*/
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Export.h"
|
|
|
|
#include "Module.h"
|
2011-03-01 14:18:26 -07:00
|
|
|
#include <ostream>
|
2010-05-12 07:27:51 -06:00
|
|
|
|
2012-06-16 04:42:56 -06:00
|
|
|
#include "DataDefs.h"
|
|
|
|
|
2012-10-11 07:34:34 -06:00
|
|
|
namespace df
|
|
|
|
{
|
|
|
|
struct tile_bitmask;
|
|
|
|
struct map_block;
|
|
|
|
}
|
|
|
|
|
2010-05-12 07:27:51 -06:00
|
|
|
namespace DFHack
|
|
|
|
{
|
2012-06-16 04:42:56 -06:00
|
|
|
typedef df::game_mode GameMode;
|
|
|
|
typedef df::game_type GameType;
|
|
|
|
|
|
|
|
#define GAMEMODE_ADVENTURE df::enums::game_mode::ADVENTURE
|
|
|
|
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* \ingroup grp_world
|
|
|
|
*/
|
2011-03-01 14:18:26 -07:00
|
|
|
struct t_gamemodes
|
|
|
|
{
|
2011-07-06 03:13:36 -06:00
|
|
|
GameMode g_mode;
|
|
|
|
GameType g_type;
|
2011-02-28 22:59:23 -07:00
|
|
|
};
|
2010-05-26 04:24:45 -06:00
|
|
|
class DFContextShared;
|
2012-01-07 08:21:31 -07:00
|
|
|
|
|
|
|
class DFHACK_EXPORT PersistentDataItem {
|
|
|
|
int id;
|
|
|
|
std::string key_value;
|
|
|
|
|
|
|
|
std::string *str_value;
|
|
|
|
int *int_values;
|
|
|
|
public:
|
|
|
|
static const int NumInts = 7;
|
|
|
|
|
2012-10-06 03:46:20 -06:00
|
|
|
bool isValid() const { return id != 0; }
|
|
|
|
int entry_id() const { return -id; }
|
|
|
|
|
|
|
|
int raw_id() const { return id; }
|
2012-01-07 08:21:31 -07:00
|
|
|
|
2012-10-06 03:46:20 -06:00
|
|
|
const std::string &key() const { return key_value; }
|
2012-01-07 08:21:31 -07:00
|
|
|
|
|
|
|
std::string &val() { return *str_value; }
|
2012-10-06 03:46:20 -06:00
|
|
|
const std::string &val() const { return *str_value; }
|
2012-01-07 08:21:31 -07:00
|
|
|
int &ival(int i) { return int_values[i]; }
|
2012-10-06 03:46:20 -06:00
|
|
|
int ival(int i) const { return int_values[i]; }
|
2012-01-07 08:21:31 -07:00
|
|
|
|
2012-11-28 08:25:01 -07:00
|
|
|
// Pack binary data into string field.
|
|
|
|
// Since DF serialization chokes on NUL bytes,
|
|
|
|
// use bit magic to ensure none of the bytes is 0.
|
|
|
|
// Choose the lowest bit for padding so that
|
|
|
|
// sign-extend can be used normally.
|
|
|
|
|
|
|
|
size_t data_size() const { return str_value->size(); }
|
|
|
|
|
|
|
|
bool check_data(size_t off, size_t sz = 1) {
|
|
|
|
return (str_value->size() >= off+sz);
|
|
|
|
}
|
|
|
|
void ensure_data(size_t off, size_t sz = 0) {
|
|
|
|
if (str_value->size() < off+sz) str_value->resize(off+sz, '\x01');
|
|
|
|
}
|
|
|
|
uint8_t *pdata(size_t off) { return (uint8_t*)&(*str_value)[off]; }
|
|
|
|
|
|
|
|
static const size_t int7_size = 1;
|
|
|
|
uint8_t get_uint7(size_t off) {
|
|
|
|
uint8_t *p = pdata(off);
|
|
|
|
return p[0]>>1;
|
|
|
|
}
|
|
|
|
int8_t get_int7(size_t off) {
|
|
|
|
uint8_t *p = pdata(off);
|
|
|
|
return int8_t(p[0])>>1;
|
|
|
|
}
|
|
|
|
void set_uint7(size_t off, uint8_t val) {
|
|
|
|
uint8_t *p = pdata(off);
|
|
|
|
p[0] = uint8_t((val<<1) | 1);
|
|
|
|
}
|
|
|
|
void set_int7(size_t off, int8_t val) { set_uint7(off, val); }
|
|
|
|
|
|
|
|
static const size_t int28_size = 4;
|
|
|
|
uint32_t get_uint28(size_t off) {
|
|
|
|
uint8_t *p = pdata(off);
|
|
|
|
return (p[0]>>1) | ((p[1]&~1U)<<6) | ((p[2]&~1U)<<13) | ((p[3]&~1U)<<20);
|
|
|
|
}
|
|
|
|
int32_t get_int28(size_t off) {
|
|
|
|
uint8_t *p = pdata(off);
|
|
|
|
return (p[0]>>1) | ((p[1]&~1U)<<6) | ((p[2]&~1U)<<13) | ((int8_t(p[3])&~1)<<20);
|
|
|
|
}
|
|
|
|
void set_uint28(size_t off, uint32_t val) {
|
|
|
|
uint8_t *p = pdata(off);
|
|
|
|
p[0] = uint8_t((val<<1) | 1);
|
|
|
|
p[1] = uint8_t((val>>6) | 1);
|
|
|
|
p[2] = uint8_t((val>>13) | 1);
|
|
|
|
p[3] = uint8_t((val>>20) | 1);
|
|
|
|
}
|
|
|
|
void set_int28(size_t off, int32_t val) { set_uint28(off, val); }
|
|
|
|
|
2012-01-07 08:21:31 -07:00
|
|
|
PersistentDataItem() : id(0), str_value(0), int_values(0) {}
|
|
|
|
PersistentDataItem(int id, const std::string &key, std::string *sv, int *iv)
|
|
|
|
: id(id), key_value(key), str_value(sv), int_values(iv) {}
|
|
|
|
};
|
|
|
|
|
2011-03-18 04:09:26 -06:00
|
|
|
/**
|
|
|
|
* The World module
|
|
|
|
* \ingroup grp_modules
|
|
|
|
* \ingroup grp_world
|
|
|
|
*/
|
2012-10-06 03:46:20 -06:00
|
|
|
namespace World
|
2010-05-12 07:27:51 -06:00
|
|
|
{
|
2011-03-18 04:09:26 -06:00
|
|
|
///true if paused, false if not
|
2012-10-06 03:46:20 -06:00
|
|
|
DFHACK_EXPORT bool ReadPauseState();
|
2011-03-18 04:09:26 -06:00
|
|
|
///true if paused, false if not
|
2012-10-06 03:46:20 -06:00
|
|
|
DFHACK_EXPORT void SetPauseState(bool paused);
|
|
|
|
|
|
|
|
DFHACK_EXPORT uint32_t ReadCurrentTick();
|
|
|
|
DFHACK_EXPORT uint32_t ReadCurrentYear();
|
|
|
|
DFHACK_EXPORT uint32_t ReadCurrentMonth();
|
|
|
|
DFHACK_EXPORT uint32_t ReadCurrentDay();
|
|
|
|
DFHACK_EXPORT uint8_t ReadCurrentWeather();
|
|
|
|
DFHACK_EXPORT void SetCurrentWeather(uint8_t weather);
|
|
|
|
DFHACK_EXPORT bool ReadGameMode(t_gamemodes& rd);
|
|
|
|
DFHACK_EXPORT bool WriteGameMode(const t_gamemodes & wr); // this is very dangerous
|
|
|
|
DFHACK_EXPORT std::string ReadWorldFolder();
|
2012-01-07 08:21:31 -07:00
|
|
|
|
2015-03-09 18:08:21 -06:00
|
|
|
DFHACK_EXPORT bool isFortressMode(df::game_type t = (df::game_type)-1);
|
|
|
|
DFHACK_EXPORT bool isAdventureMode(df::game_type t = (df::game_type)-1);
|
|
|
|
DFHACK_EXPORT bool isArena(df::game_type t = (df::game_type)-1);
|
|
|
|
DFHACK_EXPORT bool isLegends(df::game_type t = (df::game_type)-1);
|
|
|
|
|
2012-01-07 08:21:31 -07:00
|
|
|
// Store data in fake historical figure names.
|
|
|
|
// This ensures that the values are stored in save games.
|
2012-10-06 03:46:20 -06:00
|
|
|
DFHACK_EXPORT PersistentDataItem AddPersistentData(const std::string &key);
|
|
|
|
DFHACK_EXPORT PersistentDataItem GetPersistentData(const std::string &key);
|
|
|
|
DFHACK_EXPORT PersistentDataItem GetPersistentData(int entry_id);
|
2012-04-05 01:32:23 -06:00
|
|
|
// Calls GetPersistentData(key); if not found, adds and sets added to true.
|
|
|
|
// The result can still be not isValid() e.g. if the world is not loaded.
|
2012-10-06 03:46:20 -06:00
|
|
|
DFHACK_EXPORT PersistentDataItem GetPersistentData(const std::string &key, bool *added);
|
2012-04-05 01:32:23 -06:00
|
|
|
// Lists all items with the given key.
|
|
|
|
// If prefix is true, search for keys starting with key+"/".
|
|
|
|
// GetPersistentData(&vec,"",true) returns all items.
|
|
|
|
// Items have alphabetic order by key; same key ordering is undefined.
|
2012-10-06 03:46:20 -06:00
|
|
|
DFHACK_EXPORT void GetPersistentData(std::vector<PersistentDataItem> *vec,
|
|
|
|
const std::string &key, bool prefix = false);
|
2012-04-05 01:32:23 -06:00
|
|
|
// Deletes the item; returns true if success.
|
2012-10-06 03:46:20 -06:00
|
|
|
DFHACK_EXPORT bool DeletePersistentData(const PersistentDataItem &item);
|
2012-01-07 08:21:31 -07:00
|
|
|
|
2012-10-06 03:46:20 -06:00
|
|
|
DFHACK_EXPORT void ClearPersistentCache();
|
2012-10-11 07:34:34 -06:00
|
|
|
|
|
|
|
DFHACK_EXPORT df::tile_bitmask *getPersistentTilemask(const PersistentDataItem &item, df::map_block *block, bool create = false);
|
|
|
|
DFHACK_EXPORT bool deletePersistentTilemask(const PersistentDataItem &item, df::map_block *block);
|
2012-10-06 03:46:20 -06:00
|
|
|
}
|
2010-05-12 07:27:51 -06:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|