2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
#include "MiscUtils.h"
|
2011-06-24 21:35:29 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "modules/Maps.h"
|
|
|
|
#include "modules/Items.h"
|
|
|
|
#include <modules/Gui.h>
|
2011-10-26 14:18:13 -06:00
|
|
|
#include <llimits.h>
|
2012-01-26 21:54:26 -07:00
|
|
|
#include <df/caste_raw.h>
|
|
|
|
#include <df/creature_raw.h>
|
2011-06-24 21:35:29 -06:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
2012-03-03 06:38:24 -07:00
|
|
|
|
2011-06-24 21:35:29 -06:00
|
|
|
//FIXME: possible race conditions with calling kittens from the IO thread and shutdown from Core.
|
|
|
|
bool shutdown_flag = false;
|
|
|
|
bool final_flag = true;
|
2011-07-11 14:23:13 -06:00
|
|
|
bool timering = false;
|
2011-08-14 22:48:25 -06:00
|
|
|
bool trackmenu_flg = false;
|
2011-09-25 19:39:27 -06:00
|
|
|
bool trackpos_flg = false;
|
|
|
|
int32_t last_designation[3] = {-30000, -30000, -30000};
|
|
|
|
int32_t last_mouse[2] = {-1, -1};
|
2011-08-14 22:48:25 -06:00
|
|
|
uint32_t last_menu = 0;
|
2011-07-11 14:23:13 -06:00
|
|
|
uint64_t timeLast = 0;
|
2011-06-24 21:35:29 -06:00
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result kittens (color_ostream &out, vector <string> & parameters);
|
|
|
|
command_result ktimer (color_ostream &out, vector <string> & parameters);
|
|
|
|
command_result trackmenu (color_ostream &out, vector <string> & parameters);
|
|
|
|
command_result trackpos (color_ostream &out, vector <string> & parameters);
|
|
|
|
command_result colormods (color_ostream &out, vector <string> & parameters);
|
|
|
|
command_result zoom (color_ostream &out, vector <string> & parameters);
|
2011-06-19 20:29:38 -06:00
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("kittens");
|
2011-06-19 20:29:38 -06:00
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
2011-06-24 21:35:29 -06:00
|
|
|
{
|
2011-08-05 20:37:29 -06:00
|
|
|
commands.push_back(PluginCommand("nyan","NYAN CAT INVASION!",kittens, true));
|
2011-08-14 22:48:25 -06:00
|
|
|
commands.push_back(PluginCommand("ktimer","Measure time between game updates and console lag (toggle).",ktimer));
|
|
|
|
commands.push_back(PluginCommand("trackmenu","Track menu ID changes (toggle).",trackmenu));
|
2011-09-25 19:39:27 -06:00
|
|
|
commands.push_back(PluginCommand("trackpos","Track mouse and designation coords (toggle).",trackpos));
|
2012-01-26 21:54:26 -07:00
|
|
|
commands.push_back(PluginCommand("colormods","Dump colormod vectors.",colormods));
|
2012-02-16 21:30:34 -07:00
|
|
|
commands.push_back(PluginCommand("zoom","Zoom to x y z.",zoom));
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2011-06-24 21:35:29 -06:00
|
|
|
{
|
|
|
|
shutdown_flag = true;
|
|
|
|
while(!final_flag)
|
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
Core::getInstance().getConsole().msleep(60);
|
2011-06-24 21:35:29 -06:00
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
DFhackCExport command_result plugin_onupdate ( color_ostream &out )
|
2011-07-11 14:23:13 -06:00
|
|
|
{
|
|
|
|
if(timering == true)
|
|
|
|
{
|
|
|
|
uint64_t time2 = GetTimeMs64();
|
2011-07-17 03:06:45 -06:00
|
|
|
// harmless potential data race here...
|
2011-07-11 14:23:13 -06:00
|
|
|
uint64_t delta = time2-timeLast;
|
2011-07-17 03:06:45 -06:00
|
|
|
// harmless potential data race here...
|
2011-07-11 14:23:13 -06:00
|
|
|
timeLast = time2;
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Time delta = %d ms\n", delta);
|
2011-07-11 14:23:13 -06:00
|
|
|
}
|
2011-08-14 22:48:25 -06:00
|
|
|
if(trackmenu_flg)
|
|
|
|
{
|
2012-03-03 06:38:24 -07:00
|
|
|
if (last_menu != df::global::ui->main.mode)
|
2011-08-14 22:48:25 -06:00
|
|
|
{
|
2012-03-03 06:38:24 -07:00
|
|
|
last_menu = df::global::ui->main.mode;
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Menu: %d\n",last_menu);
|
2011-08-14 22:48:25 -06:00
|
|
|
}
|
|
|
|
}
|
2011-09-25 19:39:27 -06:00
|
|
|
if(trackpos_flg)
|
|
|
|
{
|
|
|
|
int32_t desig_x, desig_y, desig_z;
|
2012-03-03 06:38:24 -07:00
|
|
|
Gui::getDesignationCoords(desig_x,desig_y,desig_z);
|
2011-09-25 19:39:27 -06:00
|
|
|
if(desig_x != last_designation[0] || desig_y != last_designation[1] || desig_z != last_designation[2])
|
|
|
|
{
|
|
|
|
last_designation[0] = desig_x;
|
|
|
|
last_designation[1] = desig_y;
|
|
|
|
last_designation[2] = desig_z;
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Designation: %d %d %d\n",desig_x, desig_y, desig_z);
|
2011-09-25 19:39:27 -06:00
|
|
|
}
|
|
|
|
int mouse_x, mouse_y;
|
2012-03-03 06:38:24 -07:00
|
|
|
Gui::getMousePos(mouse_x,mouse_y);
|
2011-09-25 19:39:27 -06:00
|
|
|
if(mouse_x != last_mouse[0] || mouse_y != last_mouse[1])
|
|
|
|
{
|
|
|
|
last_mouse[0] = mouse_x;
|
|
|
|
last_mouse[1] = mouse_y;
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Mouse: %d %d\n",mouse_x, mouse_y);
|
2011-09-25 19:39:27 -06:00
|
|
|
}
|
|
|
|
}
|
2011-07-11 14:23:13 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2011-08-21 15:02:05 -06:00
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result trackmenu (color_ostream &out, vector <string> & parameters)
|
2011-08-14 22:48:25 -06:00
|
|
|
{
|
|
|
|
if(trackmenu_flg)
|
|
|
|
{
|
|
|
|
trackmenu_flg = false;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-03 06:38:24 -07:00
|
|
|
if(df::global::ui)
|
2011-08-14 22:48:25 -06:00
|
|
|
{
|
|
|
|
trackmenu_flg = true;
|
2012-03-03 06:38:24 -07:00
|
|
|
last_menu = df::global::ui->main.mode;
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Menu: %d\n",last_menu);
|
2011-08-14 22:48:25 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
out.printerr("Can't read menu state\n");
|
2011-08-14 22:48:25 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result trackpos (color_ostream &out, vector <string> & parameters)
|
2011-09-25 19:39:27 -06:00
|
|
|
{
|
|
|
|
trackpos_flg = !trackpos_flg;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-01-26 21:54:26 -07:00
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result colormods (color_ostream &out, vector <string> & parameters)
|
2011-07-30 08:47:49 -06:00
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
CoreSuspender suspend;
|
2012-01-26 21:54:26 -07:00
|
|
|
auto & vec = df::global::world->raws.creatures.alphabetic;
|
|
|
|
for(int i = 0; i < vec.size();i++)
|
2011-07-30 08:47:49 -06:00
|
|
|
{
|
2012-01-26 21:54:26 -07:00
|
|
|
df::creature_raw* rawlion = vec[i];
|
|
|
|
df::caste_raw * caste = rawlion->caste[0];
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("%s\nCaste addr 0x%x\n",rawlion->creature_id.c_str(), &caste->color_modifiers);
|
2012-01-26 21:54:26 -07:00
|
|
|
for(int j = 0; j < caste->color_modifiers.size();j++)
|
2011-07-30 08:47:49 -06:00
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("mod %d: 0x%x\n", j, caste->color_modifiers[j]);
|
2011-07-30 08:47:49 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-03 06:38:24 -07:00
|
|
|
// FIXME: move cursor properly relative to view position
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result zoom (color_ostream &out, vector <string> & parameters)
|
2012-02-16 21:30:34 -07:00
|
|
|
{
|
|
|
|
if(parameters.size() < 3)
|
|
|
|
return CR_FAILURE;
|
|
|
|
int x = atoi( parameters[0].c_str());
|
|
|
|
int y = atoi( parameters[1].c_str());
|
|
|
|
int z = atoi( parameters[2].c_str());
|
|
|
|
int xi, yi, zi;
|
2012-03-10 06:25:00 -07:00
|
|
|
CoreSuspender cs;
|
2012-03-03 06:38:24 -07:00
|
|
|
if(Gui::getCursorCoords(xi, yi, zi))
|
2012-02-16 21:30:34 -07:00
|
|
|
{
|
2012-03-03 06:38:24 -07:00
|
|
|
Gui::setCursorCoords(x,y,z);
|
2012-02-16 21:30:34 -07:00
|
|
|
}
|
2012-03-03 06:38:24 -07:00
|
|
|
Gui::setViewCoords(x,y,z);
|
2012-02-16 21:30:34 -07:00
|
|
|
}
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result ktimer (color_ostream &out, vector <string> & parameters)
|
2011-07-11 14:23:13 -06:00
|
|
|
{
|
|
|
|
if(timering)
|
|
|
|
{
|
|
|
|
timering = false;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
uint64_t timestart = GetTimeMs64();
|
2012-03-10 06:25:00 -07:00
|
|
|
{
|
|
|
|
CoreSuspender suspend;
|
|
|
|
}
|
2011-07-11 14:23:13 -06:00
|
|
|
uint64_t timeend = GetTimeMs64();
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Time to suspend = %d ms\n",timeend - timestart);
|
2011-07-17 03:06:45 -06:00
|
|
|
// harmless potential data race here...
|
2011-07-11 14:23:13 -06:00
|
|
|
timeLast = timeend;
|
|
|
|
timering = true;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result kittens (color_ostream &out, vector <string> & parameters)
|
2011-06-19 20:29:38 -06:00
|
|
|
{
|
2011-06-24 21:35:29 -06:00
|
|
|
final_flag = false;
|
2012-03-10 06:25:00 -07:00
|
|
|
assert(out.is_console());
|
|
|
|
Console &con = static_cast<Console&>(out);
|
2011-07-14 03:15:23 -06:00
|
|
|
// http://evilzone.org/creative-arts/nyan-cat-ascii/
|
|
|
|
const char * nyan []=
|
|
|
|
{
|
|
|
|
"NYAN NYAN NYAN NYAN NYAN NYAN NYAN",
|
|
|
|
"+ o + o ",
|
|
|
|
" + o + +",
|
|
|
|
"o +",
|
|
|
|
" o + + +",
|
|
|
|
"+ o o + o",
|
|
|
|
"-_-_-_-_-_-_-_,------, o ",
|
|
|
|
"_-_-_-_-_-_-_-| /\\_/\\ ",
|
|
|
|
"-_-_-_-_-_-_-~|__( ^ .^) + + ",
|
|
|
|
"_-_-_-_-_-_-_-\"\" \"\" ",
|
|
|
|
"+ o o + o",
|
|
|
|
" + +",
|
|
|
|
"o o o o +",
|
|
|
|
" o +",
|
|
|
|
"+ + o o + ",
|
|
|
|
"NYAN NYAN NYAN NYAN NYAN NYAN NYAN",
|
|
|
|
0
|
|
|
|
};
|
2011-06-19 20:29:38 -06:00
|
|
|
const char * kittenz1 []=
|
|
|
|
{
|
|
|
|
" ____",
|
|
|
|
" (. \\",
|
|
|
|
" \\ | ",
|
|
|
|
" \\ |___(\\--/)",
|
|
|
|
" __/ ( . . )",
|
|
|
|
" \"'._. '-.O.'",
|
|
|
|
" '-. \\ \"|\\",
|
|
|
|
" '.,,/'.,,mrf",
|
|
|
|
0
|
|
|
|
};
|
2011-07-14 03:15:23 -06:00
|
|
|
con.cursor(false);
|
|
|
|
con.clear();
|
2011-07-15 07:55:01 -06:00
|
|
|
Console::color_value color = Console::COLOR_BLUE;
|
2011-06-19 20:29:38 -06:00
|
|
|
while(1)
|
|
|
|
{
|
2011-06-24 21:35:29 -06:00
|
|
|
if(shutdown_flag)
|
|
|
|
{
|
|
|
|
final_flag = true;
|
2011-07-14 03:15:23 -06:00
|
|
|
con.reset_color();
|
2011-07-14 04:21:07 -06:00
|
|
|
con << std::endl << "NYAN!" << std::endl << std::flush;
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2011-07-14 03:15:23 -06:00
|
|
|
con.color(color);
|
2011-06-19 20:29:38 -06:00
|
|
|
int index = 0;
|
2011-07-14 03:15:23 -06:00
|
|
|
const char * kit = nyan[index];
|
|
|
|
con.gotoxy(1,1);
|
|
|
|
//con << "Your DF is now full of kittens!" << std::endl;
|
2011-06-19 20:29:38 -06:00
|
|
|
while (kit != 0)
|
|
|
|
{
|
2011-07-14 03:15:23 -06:00
|
|
|
con.gotoxy(1,1+index);
|
2011-07-15 16:15:20 -06:00
|
|
|
con << kit << std::endl;
|
2011-06-19 20:29:38 -06:00
|
|
|
index++;
|
2011-07-14 03:15:23 -06:00
|
|
|
kit = nyan[index];
|
2011-06-19 20:29:38 -06:00
|
|
|
}
|
2011-07-14 03:15:23 -06:00
|
|
|
con.flush();
|
|
|
|
con.msleep(60);
|
2011-07-15 07:55:01 -06:00
|
|
|
((int&)color) ++;
|
|
|
|
if(color > Console::COLOR_MAX)
|
|
|
|
color = Console::COLOR_BLUE;
|
2011-06-19 20:29:38 -06:00
|
|
|
}
|
|
|
|
}
|