Merge remote-tracking branch 'origin/master'

develop
Mike Stewart 2012-02-21 09:44:49 -08:00
commit 1322e1dd5d
7 changed files with 167 additions and 7 deletions

@ -46,6 +46,7 @@ using namespace DFHack;
#include "df/global_objects.h"
#include "df/viewscreen_dwarfmodest.h"
#include "df/viewscreen_joblistst.h"
#include "df/viewscreen_unitlistst.h"
#include "df/viewscreen_itemst.h"
#include "df/ui_unit_view_mode.h"
#include "df/ui_sidebar_menus.h"
@ -83,11 +84,11 @@ bool DFHack::dwarfmode_hotkey(Core *, df::viewscreen *top)
return !!strict_virtual_cast<df::viewscreen_dwarfmodest>(top);
}
//FIXME: this class has a second part (split off in 31.xx)!
bool DFHack::unitjobs_hotkey(Core *, df::viewscreen *top)
{
// Require the main dwarf mode screen
return !!strict_virtual_cast<df::viewscreen_joblistst>(top);
// Require the unit or jobs list
return !!strict_virtual_cast<df::viewscreen_joblistst>(top) ||
!!strict_virtual_cast<df::viewscreen_unitlistst>(top);
}
bool DFHack::item_details_hotkey(Core *, df::viewscreen *top)
@ -230,6 +231,9 @@ bool DFHack::any_job_hotkey(Core *c, df::viewscreen *top)
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_joblistst, top))
return vector_get(screen->jobs, screen->cursor_pos) != NULL;
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_unitlistst, top))
return vector_get(screen->jobs[screen->page], screen->cursor_pos[screen->page]) != NULL;
return workshop_job_hotkey(c,top);
}
@ -246,6 +250,16 @@ df::job *DFHack::getSelectedJob(Core *c, bool quiet)
return job;
}
else if (VIRTUAL_CAST_VAR(screen, df::viewscreen_unitlistst, top))
{
int page = screen->page;
df::job *job = vector_get(screen->jobs[page], screen->cursor_pos[page]);
if (!job && !quiet)
c->con.printerr("Selected unit has no job\n");
return job;
}
else
return getSelectedWorkshopJob(c, quiet);
}
@ -262,6 +276,9 @@ static df::unit *getAnyUnit(Core *c, df::viewscreen *top)
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_joblistst, top))
return vector_get(screen->units, screen->cursor_pos);
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_unitlistst, top))
return vector_get(screen->units[screen->page], screen->cursor_pos[screen->page]);
if (VIRTUAL_CAST_VAR(screen, df::viewscreen_itemst, top))
{
df::general_ref *ref = vector_get(screen->entry_ref, screen->cursor_pos);

@ -1 +1 @@
Subproject commit 6d44d3c11dd9f23e0665a1af9538a84ec627e333
Subproject commit 2262aac5158e0ee8e940d19fc6620e571f064a1d

@ -76,6 +76,7 @@ DFHACK_PLUGIN(workflow workflow.cpp)
DFHACK_PLUGIN(showmood showmood.cpp)
DFHACK_PLUGIN(fixveins fixveins.cpp)
DFHACK_PLUGIN(fixpositions fixpositions.cpp)
DFHACK_PLUGIN(follow follow.cpp)
#DFHACK_PLUGIN(versionosd versionosd.cpp)
# this is the skeleton plugin. If you want to make your own, make a copy and then change it

@ -0,0 +1,128 @@
// Make the camera follow the selected unit
#include "Core.h"
#include <Console.h>
#include <Export.h>
#include <PluginManager.h>
#include "DFHack.h"
#include "DataDefs.h"
#include "modules/Gui.h"
#include "modules/World.h"
#include "modules/Maps.h"
#include <df/unit.h>
#include <df/creature_raw.h>
using namespace DFHack;
using namespace df::enums;
command_result follow (Core * c, std::vector <std::string> & parameters);
df::unit *followedUnit;
int32_t prevX, prevY, prevZ;
DFhackCExport const char * plugin_name ( void )
{
return "follow";
}
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand(
"follow", "Follow the selected unit until camera control is released",
follow, false,
" Select a unit and run this plugin to make the camera follow it. Moving the camera yourself deactivates the plugin.\n"
));
followedUnit = 0;
prevX=prevY=prevZ = -1;
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}
// Called to notify the plugin about important state changes.
// Invoked with DF suspended, and always before the matching plugin_onupdate.
// More event codes may be added in the future.
DFhackCExport command_result plugin_onstatechange(Core* c, state_change_event event)
{
switch (event) {
case SC_GAME_LOADED:
case SC_GAME_UNLOADED:
followedUnit = 0;
prevX=prevY=prevZ = -1;
break;
default:
break;
}
return CR_OK;
}
DFhackCExport command_result plugin_onupdate ( Core * c )
{
if (!followedUnit) return CR_OK;
DFHack::World *world =c->getWorld();
if (world->ReadPauseState() && prevX==-1) return CR_OK;
Gui *gui = c->getGui();
df::coord &unitPos = followedUnit->pos;
int32_t x,y,z,w,h;
gui->getViewCoords(x,y,z);
gui->getWindowSize(w,h);
if (prevX==-1)
{
prevX = x;
prevY = y;
prevZ = z;
}
else if(prevX != x || prevY != y || prevZ != z)
{
followedUnit = 0;
prevX=prevY=prevZ = -1;
c->con.print("No longer following anything.\n");
return CR_OK;
}
uint32_t x_max, y_max, z_max;
Simple::Maps::getSize(x_max, y_max, z_max);
x_max *= 16;
y_max *= 16;
prevX = unitPos.x + w/2 >= x_max ? x_max-w+2 : (unitPos.x >= w/2 ? unitPos.x - w/2 : 0);
prevY = unitPos.y + h/2 >= y_max ? y_max-h+2 : (unitPos.y >= h/2 ? unitPos.y - h/2 : 0);
prevZ = unitPos.z;
gui->setViewCoords(prevX, prevY, prevZ);
return CR_OK;
}
command_result follow (Core * c, std::vector <std::string> & parameters)
{
if (!parameters.empty())
return CR_WRONG_USAGE;
CoreSuspender suspend(c);
followedUnit = getSelectedUnit(c);
if (followedUnit)
{
c->con.print("Unpause to begin following ");
c->con.print(df::global::world->raws.creatures.all[followedUnit->race]->name[0].c_str());
if (followedUnit->name.has_name)
{
c->con.print(" %s", followedUnit->name.first_name.c_str());
}
c->con.print(".\n");
}
else followedUnit = 0;
return CR_OK;
}

@ -208,8 +208,7 @@ command_result mapexport (Core * c, std::vector <std::string> & parameters)
df::tiletype type = b->TileTypeAt(coord);
prototile->set_type((dfproto::Tile::TileType)tileShape(type));
prototile->set_material_type((dfproto::Tile::TileMaterialType)tileMaterial(type));
prototile->set_tile_material((dfproto::Tile::TileMaterialType)tileMaterial(type));
df::coord map_pos = df::coord(b_x*16+x,b_y*16+y,z);
@ -249,6 +248,8 @@ command_result mapexport (Core * c, std::vector <std::string> & parameters)
prototile->set_material_type(constructionMaterials[map_pos].second);
}
break;
default:
break;
}
}
}

@ -36,7 +36,7 @@ message Tile
FEATURE = 3;
LAVA_STONE = 4;
MINERAL = 5;
FROZE_LIQUID = 6;
FROZEN_LIQUID = 6;
CONSTRUCTION = 7;
GRASS_LIGHT = 8;
GRASS_DARK = 9;

@ -12,6 +12,8 @@
#include "df/unit.h"
#include "df/unit_soul.h"
#include "df/historical_figure.h"
#include "df/historical_figure_info.h"
#include "df/assumed_identity.h"
#include "df/language_name.h"
#include <stdlib.h>
@ -123,7 +125,18 @@ static command_result rename(Core * c, vector <string> &parameters)
df::historical_figure *figure = df::historical_figure::find(unit->hist_figure_id);
if (figure)
{
set_nickname(&figure->name, parameters[1]);
// v0.34.01: added the vampire's assumed identity
if (figure->info && figure->info->reputation)
{
auto identity = df::assumed_identity::find(figure->info->reputation->cur_identity);
if (identity)
set_nickname(&identity->name, parameters[1]);
}
}
}
else if (cmd == "unit-profession")
{