Merge remote-tracking branch 'DFHack/develop' into develop
commit
de7ef79d76
@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace df {
|
||||||
|
struct plant;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace DFHack {
|
||||||
|
namespace Designations {
|
||||||
|
// Mark or un-mark a plant (e.g. fell trees, gather plants)
|
||||||
|
// Return value indicates whether the plant's designation was changed or not
|
||||||
|
// (This can be false if markPlant() is called on an already-designated plant, for example)
|
||||||
|
DFHACK_EXPORT bool markPlant(const df::plant *plant);
|
||||||
|
DFHACK_EXPORT bool unmarkPlant(const df::plant *plant);
|
||||||
|
DFHACK_EXPORT bool canMarkPlant(const df::plant *plant);
|
||||||
|
DFHACK_EXPORT bool canUnmarkPlant(const df::plant *plant);
|
||||||
|
DFHACK_EXPORT bool isPlantMarked(const df::plant *plant);
|
||||||
|
|
||||||
|
// Return the tile that should be designated for this plant
|
||||||
|
DFHACK_EXPORT df::coord getPlantDesignationTile(const df::plant *plant);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,153 @@
|
|||||||
|
#include "DataDefs.h"
|
||||||
|
#include "Error.h"
|
||||||
|
|
||||||
|
#include "modules/Designations.h"
|
||||||
|
#include "modules/Job.h"
|
||||||
|
#include "modules/Maps.h"
|
||||||
|
|
||||||
|
#include "df/job.h"
|
||||||
|
#include "df/map_block.h"
|
||||||
|
#include "df/plant.h"
|
||||||
|
#include "df/plant_tree_info.h"
|
||||||
|
#include "df/plant_tree_tile.h"
|
||||||
|
#include "df/tile_dig_designation.h"
|
||||||
|
#include "df/world.h"
|
||||||
|
|
||||||
|
using namespace DFHack;
|
||||||
|
using namespace df::enums;
|
||||||
|
|
||||||
|
using df::global::world;
|
||||||
|
|
||||||
|
static df::map_block *getPlantBlock(const df::plant *plant)
|
||||||
|
{
|
||||||
|
if (!world)
|
||||||
|
return nullptr;
|
||||||
|
return Maps::getTileBlock(Designations::getPlantDesignationTile(plant));
|
||||||
|
}
|
||||||
|
|
||||||
|
df::coord Designations::getPlantDesignationTile(const df::plant *plant)
|
||||||
|
{
|
||||||
|
CHECK_NULL_POINTER(plant);
|
||||||
|
|
||||||
|
if (!plant->tree_info)
|
||||||
|
return plant->pos;
|
||||||
|
|
||||||
|
int dimx = plant->tree_info->dim_x;
|
||||||
|
int dimy = plant->tree_info->dim_y;
|
||||||
|
int cx = dimx / 2;
|
||||||
|
int cy = dimy / 2;
|
||||||
|
|
||||||
|
// Find the southeast trunk tile
|
||||||
|
int x = cx;
|
||||||
|
int y = cy;
|
||||||
|
|
||||||
|
while (x + 1 < dimx && y + 1 < dimy)
|
||||||
|
{
|
||||||
|
if (plant->tree_info->body[0][(y * dimx) + (x + 1)].bits.trunk)
|
||||||
|
++x;
|
||||||
|
else if (plant->tree_info->body[0][((y + 1) * dimx) + x].bits.trunk)
|
||||||
|
++y;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return df::coord(plant->pos.x - cx + x, plant->pos.y - cy + y, plant->pos.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Designations::isPlantMarked(const df::plant *plant)
|
||||||
|
{
|
||||||
|
CHECK_NULL_POINTER(plant);
|
||||||
|
|
||||||
|
df::coord des_pos = getPlantDesignationTile(plant);
|
||||||
|
df::map_block *block = Maps::getTileBlock(des_pos);
|
||||||
|
if (!block)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (block->designation[des_pos.x % 16][des_pos.y % 16].bits.dig == tile_dig_designation::Default)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for (auto *link = world->job_list.next; link; link = link->next)
|
||||||
|
{
|
||||||
|
df::job *job = link->item;
|
||||||
|
if (!job)
|
||||||
|
continue;
|
||||||
|
if (job->job_type != job_type::FellTree && job->job_type != job_type::GatherPlants)
|
||||||
|
continue;
|
||||||
|
if (job->pos == des_pos)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Designations::canMarkPlant(const df::plant *plant)
|
||||||
|
{
|
||||||
|
CHECK_NULL_POINTER(plant);
|
||||||
|
|
||||||
|
if (!getPlantBlock(plant))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return !isPlantMarked(plant);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Designations::markPlant(const df::plant *plant)
|
||||||
|
{
|
||||||
|
CHECK_NULL_POINTER(plant);
|
||||||
|
|
||||||
|
if (canMarkPlant(plant))
|
||||||
|
{
|
||||||
|
df::coord des_pos = getPlantDesignationTile(plant);
|
||||||
|
df::map_block *block = Maps::getTileBlock(des_pos);
|
||||||
|
block->designation[des_pos.x % 16][des_pos.y % 16].bits.dig = tile_dig_designation::Default;
|
||||||
|
block->flags.bits.designated = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Designations::canUnmarkPlant(const df::plant *plant)
|
||||||
|
{
|
||||||
|
CHECK_NULL_POINTER(plant);
|
||||||
|
|
||||||
|
if (!getPlantBlock(plant))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return isPlantMarked(plant);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Designations::unmarkPlant(const df::plant *plant)
|
||||||
|
{
|
||||||
|
CHECK_NULL_POINTER(plant);
|
||||||
|
|
||||||
|
if (canUnmarkPlant(plant))
|
||||||
|
{
|
||||||
|
df::coord des_pos = getPlantDesignationTile(plant);
|
||||||
|
df::map_block *block = Maps::getTileBlock(des_pos);
|
||||||
|
block->designation[des_pos.x % 16][des_pos.y % 16].bits.dig = tile_dig_designation::No;
|
||||||
|
block->flags.bits.designated = true;
|
||||||
|
|
||||||
|
auto *link = world->job_list.next;
|
||||||
|
while (link)
|
||||||
|
{
|
||||||
|
auto *next = link->next;
|
||||||
|
df::job *job = link->item;
|
||||||
|
|
||||||
|
if (job &&
|
||||||
|
(job->job_type == job_type::FellTree || job->job_type == job_type::GatherPlants) &&
|
||||||
|
job->pos == des_pos)
|
||||||
|
{
|
||||||
|
Job::removeJob(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
link = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
Subproject commit 9b834c089efb4657d43a8fa4f8f0822e8224e576
|
Subproject commit b48397cf5b4c954a098151943f7314a1a6eacf90
|
@ -1 +1 @@
|
|||||||
Subproject commit 1925760b2f611d246d1715a2e3cfb591a02ef00b
|
Subproject commit 1ffdc984d0c3d50e790b9ff5991c02fb21dec463
|
@ -0,0 +1,41 @@
|
|||||||
|
#include "df/viewscreen_dwarfmodest.h"
|
||||||
|
|
||||||
|
using df::global::ui;
|
||||||
|
|
||||||
|
struct hotkey_clear_hook : df::viewscreen_dwarfmodest {
|
||||||
|
typedef df::viewscreen_dwarfmodest interpose_base;
|
||||||
|
|
||||||
|
DEFINE_VMETHOD_INTERPOSE(void, render, ())
|
||||||
|
{
|
||||||
|
INTERPOSE_NEXT(render)();
|
||||||
|
if (ui->main.mode == df::ui_sidebar_mode::Hotkeys)
|
||||||
|
{
|
||||||
|
int x = 26, y = 19;
|
||||||
|
OutputHotkeyString(x, y, "Clear", df::interface_key::CUSTOM_C, false, 0, COLOR_WHITE, COLOR_LIGHTRED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_VMETHOD_INTERPOSE(void, feed, (set<df::interface_key> *input))
|
||||||
|
{
|
||||||
|
if (ui->main.mode == df::ui_sidebar_mode::Hotkeys &&
|
||||||
|
input->count(df::interface_key::CUSTOM_C) &&
|
||||||
|
!ui->main.in_rename_hotkey)
|
||||||
|
{
|
||||||
|
auto &hotkey = ui->main.hotkeys[ui->main.selected_hotkey];
|
||||||
|
hotkey.name = "";
|
||||||
|
hotkey.cmd = df::ui_hotkey::T_cmd::None;
|
||||||
|
hotkey.x = 0;
|
||||||
|
hotkey.y = 0;
|
||||||
|
hotkey.z = 0;
|
||||||
|
hotkey.unit_id = 0;
|
||||||
|
hotkey.item_id = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
INTERPOSE_NEXT(feed)(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
IMPLEMENT_VMETHOD_INTERPOSE(hotkey_clear_hook, feed);
|
||||||
|
IMPLEMENT_VMETHOD_INTERPOSE(hotkey_clear_hook, render);
|
@ -1 +1 @@
|
|||||||
Subproject commit cf367974b5e1513d454b2988d45122e98cd28f52
|
Subproject commit e9c3119e751c3e2073eb02bbcda01d140cc6ae4a
|
Loading…
Reference in New Issue