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
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Export.h"
|
2012-01-28 13:12:41 -07:00
|
|
|
#include "DataDefs.h"
|
2012-12-18 18:28:30 -07:00
|
|
|
#include "Types.h"
|
2016-08-13 19:44:01 -06:00
|
|
|
#include "modules/Items.h"
|
|
|
|
#include "modules/Maps.h"
|
|
|
|
|
2012-01-28 13:12:41 -07:00
|
|
|
#include "df/building.h"
|
2014-09-07 13:52:07 -06:00
|
|
|
#include "df/building_stockpilest.h"
|
2012-12-18 18:28:30 -07:00
|
|
|
#include "df/building_type.h"
|
2012-03-15 19:09:56 -06:00
|
|
|
#include "df/civzone_type.h"
|
2016-08-13 19:44:01 -06:00
|
|
|
#include "df/construction_type.h"
|
2012-02-18 10:34:52 -07:00
|
|
|
#include "df/furnace_type.h"
|
2014-09-07 13:52:07 -06:00
|
|
|
#include "df/item.h"
|
2012-02-18 10:34:52 -07:00
|
|
|
#include "df/shop_type.h"
|
|
|
|
#include "df/siegeengine_type.h"
|
|
|
|
#include "df/trap_type.h"
|
2016-08-13 19:44:01 -06:00
|
|
|
#include "df/workshop_type.h"
|
2011-03-18 01:53:59 -06:00
|
|
|
|
2012-04-29 11:07:39 -06:00
|
|
|
namespace df
|
|
|
|
{
|
|
|
|
struct job_item;
|
|
|
|
struct item;
|
|
|
|
struct building_extents;
|
2012-05-06 01:22:55 -06:00
|
|
|
struct building_civzonest;
|
2012-04-29 11:07:39 -06:00
|
|
|
}
|
|
|
|
|
2010-04-09 08:43:00 -06:00
|
|
|
namespace DFHack
|
|
|
|
{
|
2012-01-07 18:22:13 -07:00
|
|
|
namespace Buildings
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Structure for holding a read DF building object
|
|
|
|
* \ingroup grp_buildings
|
|
|
|
*/
|
|
|
|
struct t_building
|
|
|
|
{
|
|
|
|
uint32_t x1;
|
|
|
|
uint32_t y1;
|
|
|
|
uint32_t x2;
|
|
|
|
uint32_t y2;
|
|
|
|
uint32_t z;
|
|
|
|
t_matglossPair material;
|
2012-02-18 10:34:52 -07:00
|
|
|
df::building_type type;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
int16_t subtype;
|
2012-03-15 19:09:56 -06:00
|
|
|
df::civzone_type civzone_type;
|
2012-02-18 10:34:52 -07:00
|
|
|
df::furnace_type furnace_type;
|
|
|
|
df::workshop_type workshop_type;
|
|
|
|
df::construction_type construction_type;
|
|
|
|
df::shop_type shop_type;
|
|
|
|
df::siegeengine_type siegeengine_type;
|
|
|
|
df::trap_type trap_type;
|
|
|
|
};
|
2012-01-07 18:22:13 -07:00
|
|
|
int32_t custom_type;
|
2012-01-28 13:12:41 -07:00
|
|
|
df::building * origin;
|
2012-01-07 18:22:13 -07:00
|
|
|
};
|
2011-04-10 05:12:28 -06:00
|
|
|
|
2012-01-07 18:22:13 -07:00
|
|
|
/**
|
|
|
|
* The Buildings module - allows reading DF buildings
|
|
|
|
* \ingroup grp_modules
|
|
|
|
* \ingroup grp_buildings
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT uint32_t getNumBuildings ();
|
2011-04-10 05:12:28 -06:00
|
|
|
|
2012-01-07 18:22:13 -07:00
|
|
|
/**
|
|
|
|
* read building by index
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT bool Read (const uint32_t index, t_building & building);
|
2011-04-10 05:12:28 -06:00
|
|
|
|
2012-01-07 18:22:13 -07:00
|
|
|
/**
|
|
|
|
* read mapping from custom_type value to building RAW name
|
|
|
|
* custom_type of -1 implies ordinary building
|
|
|
|
*/
|
2012-03-10 08:03:11 -07:00
|
|
|
DFHACK_EXPORT bool ReadCustomWorkshopTypes(std::map <uint32_t, std::string> & btypes);
|
2011-04-10 05:12:28 -06:00
|
|
|
|
2012-11-12 08:17:32 -07:00
|
|
|
DFHACK_EXPORT df::general_ref *getGeneralRef(df::building *building, df::general_ref_type type);
|
|
|
|
DFHACK_EXPORT df::specific_ref *getSpecificRef(df::building *building, df::specific_ref_type type);
|
|
|
|
|
2012-08-24 08:26:18 -06:00
|
|
|
/**
|
|
|
|
* Sets the owner unit for the building.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT bool setOwner(df::building *building, df::unit *owner);
|
|
|
|
|
2012-05-06 01:22:55 -06:00
|
|
|
/**
|
2012-05-01 09:55:25 -06:00
|
|
|
* Find the building located at the specified tile.
|
|
|
|
* Does not work on civzones.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT df::building *findAtTile(df::coord pos);
|
|
|
|
|
2012-05-06 01:22:55 -06:00
|
|
|
/**
|
|
|
|
* Find civzones located at the specified tile.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT bool findCivzonesAt(std::vector<df::building_civzonest*> *pvec, df::coord pos);
|
|
|
|
|
2012-04-29 11:07:39 -06:00
|
|
|
/**
|
|
|
|
* Allocates a building object using this type and position.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT df::building *allocInstance(df::coord pos, df::building_type type, int subtype = -1, int custom = -1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets size and center to the correct dimensions of the building.
|
|
|
|
* If part of the original size value was used, returns true.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT bool getCorrectSize(df::coord2d &size, df::coord2d ¢er,
|
|
|
|
df::building_type type, int subtype = -1, int custom = -1,
|
|
|
|
int direction = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the tiles are free to be built upon.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT bool checkFreeTiles(df::coord pos, df::coord2d size,
|
2012-05-01 08:55:30 -06:00
|
|
|
df::building_extents *ext = NULL,
|
|
|
|
bool create_ext = false, bool allow_occupied = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of tiles included by the extent, or defval.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT int countExtentTiles(df::building_extents *ext, int defval = -1);
|
|
|
|
|
2012-05-06 01:22:55 -06:00
|
|
|
/**
|
|
|
|
* Checks if the building contains the specified tile.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT bool containsTile(df::building *bld, df::coord2d tile, bool room = false);
|
|
|
|
|
2012-05-01 08:55:30 -06:00
|
|
|
/**
|
|
|
|
* Checks if the area has support from the terrain.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT bool hasSupport(df::coord pos, df::coord2d size);
|
2012-04-29 11:07:39 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the size of the building, using size and direction as guidance.
|
|
|
|
* Returns true if the building can be created at its position, using that size.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT bool setSize(df::building *bld, df::coord2d size, int direction = 0);
|
|
|
|
|
2012-05-01 08:55:30 -06:00
|
|
|
/**
|
|
|
|
* Decodes the size of the building into pos and size.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT std::pair<df::coord,df::coord2d> getSize(df::building *bld);
|
|
|
|
|
2012-05-06 09:09:11 -06:00
|
|
|
/**
|
|
|
|
* Constructs an abstract building, i.e. stockpile or civzone.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT bool constructAbstract(df::building *bld);
|
|
|
|
|
2012-04-29 11:07:39 -06:00
|
|
|
/**
|
|
|
|
* Initiates construction of the building, using specified items as inputs.
|
|
|
|
* Returns true if success.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT bool constructWithItems(df::building *bld, std::vector<df::item*> items);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initiates construction of the building, using specified item filters.
|
|
|
|
* Assumes immediate ownership of the item objects, and deletes them in case of error.
|
|
|
|
* Returns true if success.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT bool constructWithFilters(df::building *bld, std::vector<df::job_item*> items);
|
|
|
|
|
2012-05-06 09:09:11 -06:00
|
|
|
/**
|
|
|
|
* Deconstructs or queues deconstruction of a building.
|
|
|
|
* Returns true if the building has been destroyed instantly.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT bool deconstruct(df::building *bld);
|
|
|
|
|
2012-12-18 18:28:30 -07:00
|
|
|
void updateBuildings(color_ostream& out, void* ptr);
|
2013-01-01 20:22:31 -07:00
|
|
|
void clearBuildings(color_ostream& out);
|
2012-12-18 18:28:30 -07:00
|
|
|
|
2014-09-07 13:52:07 -06:00
|
|
|
/**
|
|
|
|
* Iterates over the items stored on a stockpile.
|
|
|
|
* (For stockpiles with containers, yields the containers, not their contents.)
|
2015-02-14 20:53:06 -07:00
|
|
|
*
|
2014-09-07 13:52:07 -06:00
|
|
|
* Usage:
|
2015-02-14 20:53:06 -07:00
|
|
|
*
|
2014-09-07 13:52:07 -06:00
|
|
|
* Buildings::StockpileIterator stored;
|
|
|
|
* for (stored.begin(stockpile); !stored.done(); ++stored) {
|
|
|
|
* df::item *item = *stored;
|
|
|
|
* }
|
2015-02-14 20:53:06 -07:00
|
|
|
*
|
2014-09-07 13:52:07 -06:00
|
|
|
* Implementation detail: Uses tile blocks for speed.
|
|
|
|
* For each tile block that contains at least part of the stockpile,
|
|
|
|
* starting at the top left and moving right, row by row,
|
|
|
|
* the block's items are checked for anything on the ground within that stockpile.
|
|
|
|
*/
|
|
|
|
class DFHACK_EXPORT StockpileIterator : public std::iterator<std::input_iterator_tag, df::item>
|
|
|
|
{
|
|
|
|
df::building_stockpilest* stockpile;
|
|
|
|
df::map_block* block;
|
|
|
|
size_t current;
|
|
|
|
df::item *item;
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2014-09-07 13:52:07 -06:00
|
|
|
public:
|
|
|
|
StockpileIterator() {
|
|
|
|
stockpile = NULL;
|
|
|
|
block = NULL;
|
|
|
|
item = NULL;
|
|
|
|
}
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2016-08-13 19:44:01 -06:00
|
|
|
StockpileIterator& operator++();
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2014-09-07 13:52:07 -06:00
|
|
|
void begin(df::building_stockpilest* sp) {
|
|
|
|
stockpile = sp;
|
|
|
|
operator++();
|
|
|
|
}
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2014-09-07 13:52:07 -06:00
|
|
|
df::item* operator*() {
|
|
|
|
return item;
|
|
|
|
}
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2014-09-07 13:52:07 -06:00
|
|
|
bool done() {
|
|
|
|
return block == NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-07 14:10:27 -06:00
|
|
|
/**
|
|
|
|
* Collects items stored on a stockpile into a vector.
|
|
|
|
*/
|
|
|
|
DFHACK_EXPORT void getStockpileContents(df::building_stockpilest *stockpile, std::vector<df::item*> *items);
|
2015-01-29 11:54:33 -07:00
|
|
|
DFHACK_EXPORT bool isActivityZone(df::building * building);
|
|
|
|
DFHACK_EXPORT bool isPenPasture(df::building * building);
|
|
|
|
DFHACK_EXPORT bool isPitPond(df::building * building);
|
|
|
|
DFHACK_EXPORT bool isActive(df::building * building);
|
2016-06-05 07:09:07 -06:00
|
|
|
DFHACK_EXPORT bool isHospital(df::building * building);
|
|
|
|
DFHACK_EXPORT bool isAnimalTraining(df::building * building);
|
2014-09-07 14:10:27 -06:00
|
|
|
|
2015-01-29 13:02:54 -07:00
|
|
|
DFHACK_EXPORT df::building* findPenPitAt(df::coord coord);
|
2012-01-07 18:22:13 -07:00
|
|
|
}
|
|
|
|
}
|