2019-06-01 15:30:26 -06:00
|
|
|
#include <array>
|
2018-06-30 12:10:51 -06:00
|
|
|
#include <atomic>
|
2016-08-13 19:44:01 -06:00
|
|
|
#include <vector>
|
2018-07-02 09:48:33 -06:00
|
|
|
#include <random>
|
2016-08-13 19:44:01 -06:00
|
|
|
#include <string>
|
2018-07-02 09:48:33 -06:00
|
|
|
#include <thread>
|
2016-08-13 19:44:01 -06:00
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Console.h"
|
2016-08-13 19:44:01 -06:00
|
|
|
#include "Core.h"
|
2018-07-02 09:48:33 -06:00
|
|
|
#include "Debug.h"
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Export.h"
|
|
|
|
#include "MiscUtils.h"
|
2016-08-13 19:44:01 -06:00
|
|
|
#include "PluginManager.h"
|
2018-07-02 09:48:33 -06:00
|
|
|
#include "Signal.hpp"
|
2016-08-13 19:44:01 -06:00
|
|
|
|
|
|
|
#include "modules/Gui.h"
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "modules/Items.h"
|
2016-08-13 19:44:01 -06:00
|
|
|
#include "modules/Maps.h"
|
|
|
|
|
|
|
|
#include "df/caste_raw.h"
|
|
|
|
#include "df/creature_raw.h"
|
|
|
|
#include "df/world.h"
|
2011-06-24 21:35:29 -06:00
|
|
|
|
2019-06-01 15:30:26 -06:00
|
|
|
// for MSVC alignas(64) issues
|
|
|
|
#ifdef WIN32
|
|
|
|
#define _DISABLE_EXTENDED_ALIGNED_STORAGE
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2018-06-01 08:02:05 -06:00
|
|
|
DFHACK_PLUGIN("kittens");
|
2013-09-30 03:19:51 -06:00
|
|
|
DFHACK_PLUGIN_IS_ENABLED(is_enabled);
|
2018-06-01 08:02:05 -06:00
|
|
|
REQUIRE_GLOBAL(ui);
|
|
|
|
REQUIRE_GLOBAL(world);
|
2013-09-30 03:19:51 -06:00
|
|
|
|
2018-07-02 09:48:33 -06:00
|
|
|
namespace DFHack {
|
|
|
|
DBG_DECLARE(kittens,command);
|
|
|
|
}
|
|
|
|
|
2018-06-30 12:10:51 -06:00
|
|
|
std::atomic<bool> shutdown_flag{false};
|
|
|
|
std::atomic<bool> final_flag{true};
|
|
|
|
std::atomic<bool> timering{false};
|
|
|
|
std::atomic<bool> trackmenu_flg{false};
|
|
|
|
std::atomic<uint8_t> trackpos_flg{0};
|
|
|
|
std::atomic<uint8_t> statetrack{0};
|
2011-09-25 19:39:27 -06:00
|
|
|
int32_t last_designation[3] = {-30000, -30000, -30000};
|
|
|
|
int32_t last_mouse[2] = {-1, -1};
|
2018-06-01 08:02:05 -06:00
|
|
|
df::ui_sidebar_mode last_menu = df::ui_sidebar_mode::Default;
|
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);
|
2012-03-31 18:56:54 -06:00
|
|
|
command_result trackstate (color_ostream &out, vector <string> & parameters);
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result colormods (color_ostream &out, vector <string> & parameters);
|
2018-07-02 09:48:33 -06:00
|
|
|
command_result sharedsignal (color_ostream &out, vector <string> & parameters);
|
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
|
|
|
{
|
2015-04-01 15:02:33 -06:00
|
|
|
commands.push_back(PluginCommand("nyan","NYAN CAT INVASION!",kittens));
|
2015-11-09 20:37:45 -07:00
|
|
|
commands.push_back(PluginCommand("ktimer","Measure time between game updates and console lag.",ktimer));
|
2011-08-14 22:48:25 -06:00
|
|
|
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-03-31 18:56:54 -06:00
|
|
|
commands.push_back(PluginCommand("trackstate","Track world and map state (toggle).",trackstate));
|
2012-01-26 21:54:26 -07:00
|
|
|
commands.push_back(PluginCommand("colormods","Dump colormod vectors.",colormods));
|
2018-07-02 09:48:33 -06:00
|
|
|
commands.push_back(PluginCommand("sharedsignal","Test Signal with signal_shared_tag",sharedsignal));
|
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-31 18:56:54 -06:00
|
|
|
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
|
|
|
|
{
|
2012-03-31 19:46:17 -06:00
|
|
|
if(!statetrack)
|
|
|
|
return CR_OK;
|
2012-03-31 18:56:54 -06:00
|
|
|
switch (event) {
|
|
|
|
case SC_MAP_LOADED:
|
|
|
|
out << "Map loaded" << endl;
|
|
|
|
break;
|
|
|
|
case SC_MAP_UNLOADED:
|
|
|
|
out << "Map unloaded" << endl;
|
|
|
|
break;
|
|
|
|
case SC_WORLD_LOADED:
|
|
|
|
out << "World loaded" << endl;
|
|
|
|
break;
|
|
|
|
case SC_WORLD_UNLOADED:
|
|
|
|
out << "World unloaded" << endl;
|
|
|
|
break;
|
|
|
|
case SC_VIEWSCREEN_CHANGED:
|
|
|
|
out << "Screen changed" << endl;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
out << "Something else is happening, nobody knows what..." << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2018-06-30 12:10:51 -06:00
|
|
|
if(timering)
|
2011-07-11 14:23:13 -06:00
|
|
|
{
|
|
|
|
uint64_t time2 = GetTimeMs64();
|
|
|
|
uint64_t delta = time2-timeLast;
|
|
|
|
timeLast = time2;
|
2018-06-20 10:03:14 -06:00
|
|
|
out.print("Time delta = %d ms\n", int(delta));
|
2011-07-11 14:23:13 -06:00
|
|
|
}
|
2011-08-14 22:48:25 -06:00
|
|
|
if(trackmenu_flg)
|
|
|
|
{
|
2018-06-01 08:02:05 -06:00
|
|
|
if (last_menu != ui->main.mode)
|
2011-08-14 22:48:25 -06:00
|
|
|
{
|
2018-06-01 08:02:05 -06:00
|
|
|
last_menu = 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
|
|
|
}
|
2022-09-18 09:40:22 -06:00
|
|
|
df::coord mousePos = Gui::getMousePos();
|
2022-09-18 09:19:02 -06:00
|
|
|
if(mousePos.x != last_mouse[0] || mousePos.y != last_mouse[1])
|
2011-09-25 19:39:27 -06:00
|
|
|
{
|
2022-09-18 09:19:02 -06:00
|
|
|
last_mouse[0] = mousePos.x;
|
|
|
|
last_mouse[1] = mousePos.y;
|
|
|
|
out.print("Mouse: %d %d\n",mousePos.x, mousePos.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
|
|
|
{
|
2018-06-30 12:10:51 -06:00
|
|
|
bool is_running = trackmenu_flg.exchange(false);
|
|
|
|
if(is_running)
|
2011-08-14 22:48:25 -06:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-01 08:02:05 -06:00
|
|
|
is_enabled = true;
|
|
|
|
last_menu = ui->main.mode;
|
|
|
|
out.print("Menu: %d\n",last_menu);
|
2018-06-30 12:10:51 -06:00
|
|
|
trackmenu_flg = true;
|
2018-06-01 08:02:05 -06:00
|
|
|
return CR_OK;
|
2011-08-14 22:48:25 -06:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2018-06-30 12:10:51 -06:00
|
|
|
trackpos_flg.fetch_xor(1);
|
2013-09-30 03:19:51 -06:00
|
|
|
is_enabled = true;
|
2011-09-25 19:39:27 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-01-26 21:54:26 -07:00
|
|
|
|
2012-03-31 18:56:54 -06:00
|
|
|
command_result trackstate ( color_ostream& out, vector< string >& parameters )
|
|
|
|
{
|
2018-06-30 12:10:51 -06:00
|
|
|
statetrack.fetch_xor(1);
|
2012-03-31 18:56:54 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
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;
|
2018-06-01 08:02:05 -06:00
|
|
|
auto & vec = world->raws.creatures.alphabetic;
|
|
|
|
for(df::creature_raw* rawlion : vec)
|
2011-07-30 08:47:49 -06:00
|
|
|
{
|
2012-01-26 21:54:26 -07:00
|
|
|
df::caste_raw * caste = rawlion->caste[0];
|
2018-06-20 10:03:14 -06:00
|
|
|
out.print("%s\nCaste addr %p\n",rawlion->creature_id.c_str(), &caste->color_modifiers);
|
2018-06-01 08:02:05 -06:00
|
|
|
for(size_t j = 0; j < caste->color_modifiers.size();j++)
|
2011-07-30 08:47:49 -06:00
|
|
|
{
|
2018-06-20 10:03:14 -06:00
|
|
|
out.print("mod %zd: %p\n", j, caste->color_modifiers[j]);
|
2011-07-30 08:47:49 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-06-30 12:10:51 -06:00
|
|
|
bool is_running = timering.exchange(false);
|
|
|
|
if(is_running)
|
2011-07-11 14:23:13 -06:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
uint64_t timestart = GetTimeMs64();
|
2012-03-10 06:25:00 -07:00
|
|
|
{
|
|
|
|
CoreSuspender suspend;
|
2018-06-30 12:10:51 -06:00
|
|
|
uint64_t timeend = GetTimeMs64();
|
|
|
|
timeLast = timeend;
|
|
|
|
timering = true;
|
|
|
|
out.print("Time to suspend = %d ms\n", int(timeend - timestart));
|
2012-03-10 06:25:00 -07:00
|
|
|
}
|
2013-09-30 03:19:51 -06:00
|
|
|
is_enabled = true;
|
2011-07-11 14:23:13 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2018-07-02 09:48:33 -06:00
|
|
|
struct Connected;
|
|
|
|
using shared = std::shared_ptr<Connected>;
|
|
|
|
using weak = std::weak_ptr<Connected>;
|
|
|
|
|
|
|
|
static constexpr std::chrono::microseconds delay{1};
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
struct ClearMem : public ConnectedBase {
|
|
|
|
~ClearMem()
|
|
|
|
{
|
|
|
|
memset(reinterpret_cast<void*>(this), 0xDE, sizeof(Derived));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Connected : public ClearMem<Connected> {
|
2019-06-01 15:30:26 -06:00
|
|
|
using Sig = Signal<void(uint32_t), signal_shared_tag>;
|
2018-07-02 09:48:33 -06:00
|
|
|
std::array<Sig::Connection,4> con;
|
|
|
|
Sig signal;
|
|
|
|
weak other;
|
|
|
|
Sig::weak_ptr other_sig;
|
|
|
|
color_ostream *out;
|
|
|
|
int id;
|
|
|
|
uint32_t count;
|
|
|
|
uint32_t caller;
|
|
|
|
alignas(64) std::atomic<uint32_t> callee;
|
|
|
|
Connected() = default;
|
|
|
|
Connected(int id) :
|
|
|
|
Connected{}
|
|
|
|
{
|
|
|
|
this->id = id;
|
|
|
|
}
|
|
|
|
void connect(color_ostream& o, shared& b, size_t pos, uint32_t c)
|
|
|
|
{
|
|
|
|
out = &o;
|
|
|
|
count = c*2;
|
|
|
|
other = b;
|
|
|
|
other_sig = b->signal.weak_from_this();
|
|
|
|
// Externally synchronized object destruction is only safe to this
|
|
|
|
// connect.
|
|
|
|
con[pos] = b->signal.connect(
|
2019-06-01 15:30:26 -06:00
|
|
|
[this](uint32_t) {
|
2018-07-02 09:48:33 -06:00
|
|
|
uint32_t old = callee.fetch_add(1);
|
2021-09-06 23:16:21 -06:00
|
|
|
assert(old != 0xDEDEDEDE); (void)old;
|
2018-07-02 09:48:33 -06:00
|
|
|
std::this_thread::sleep_for(delay);
|
|
|
|
assert(callee != 0xDEDEDEDE);
|
|
|
|
});
|
|
|
|
// Shared object managed object with possibility of destruction while
|
|
|
|
// other threads calling emit must pass the shared_ptr to connect.
|
|
|
|
Connected *bptr = b.get();
|
|
|
|
b->con[pos] = signal.connect(b,
|
|
|
|
[bptr](int) {
|
|
|
|
uint32_t old = bptr->callee.fetch_add(1);
|
2021-09-06 23:16:21 -06:00
|
|
|
assert(old != 0xDEDEDEDE); (void)old;
|
2018-07-02 09:48:33 -06:00
|
|
|
std::this_thread::sleep_for(delay);
|
|
|
|
assert(bptr->callee != 0xDEDEDEDE);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
void reconnect(size_t pos) {
|
|
|
|
auto b = other.lock();
|
|
|
|
if (!b)
|
|
|
|
return;
|
|
|
|
// Not required to use Sig::lock because other holds strong reference to
|
|
|
|
// Signal. But this just shows how weak_ref could be used.
|
|
|
|
auto sig = Sig::lock(other_sig);
|
|
|
|
if (!sig)
|
|
|
|
return;
|
|
|
|
con[pos] = sig->connect(b,
|
2019-06-01 15:30:26 -06:00
|
|
|
[this](uint32_t) {
|
2018-07-02 09:48:33 -06:00
|
|
|
uint32_t old = callee.fetch_add(1);
|
2021-09-06 23:16:21 -06:00
|
|
|
assert(old != 0xDEDEDEDE); (void)old;
|
2018-07-02 09:48:33 -06:00
|
|
|
std::this_thread::sleep_for(delay);
|
|
|
|
assert(callee != 0xDEDEDEDE);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
void connect(color_ostream& o, shared& a, shared& b,size_t pos, uint32_t c)
|
|
|
|
{
|
|
|
|
out = &o;
|
|
|
|
count = c;
|
|
|
|
con[pos] = b->signal.connect(a,
|
2019-06-01 15:30:26 -06:00
|
|
|
[this](uint32_t) {
|
2018-07-02 09:48:33 -06:00
|
|
|
uint32_t old = callee.fetch_add(1);
|
2021-09-06 23:16:21 -06:00
|
|
|
assert(old != 0xDEDEDEDE); (void)old;
|
2018-07-02 09:48:33 -06:00
|
|
|
std::this_thread::sleep_for(delay);
|
|
|
|
assert(callee != 0xDEDEDEDE);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
Connected* operator->() noexcept
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
~Connected() {
|
|
|
|
INFO(command,*out).print("Connected %d had %d count. "
|
|
|
|
"It was caller %d times. "
|
|
|
|
"It was callee %d times.\n",
|
|
|
|
id, count, caller, callee.load());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
command_result sharedsignal (color_ostream &out, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
using rng_t = std::linear_congruential_engine<uint32_t, 747796405U, 2891336453U, 0>;
|
|
|
|
rng_t rng(std::random_device{}());
|
|
|
|
size_t count = 10;
|
|
|
|
if (0 < parameters.size()) {
|
|
|
|
std::stringstream ss(parameters[0]);
|
|
|
|
ss >> count;
|
|
|
|
DEBUG(command, out) << "Parsed " << count
|
|
|
|
<< " from paramters[0] '" << parameters[0] << '\'' << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::uniform_int_distribution<uint32_t> dis(4096,8192);
|
|
|
|
out << "Running signal_shared_tag destruction test "
|
|
|
|
<< count << " times" << std::endl;
|
|
|
|
for (size_t nr = 0; nr < count; ++nr) {
|
|
|
|
std::array<std::thread,4> t{};
|
|
|
|
// Make an object which destruction is protected by std::thread::join()
|
|
|
|
Connected external{static_cast<int>(t.size())};
|
|
|
|
TRACE(command, out) << "begin " << std::endl;
|
|
|
|
{
|
|
|
|
int id = 0;
|
|
|
|
// Make objects that are automatically protected using weak_ptr
|
|
|
|
// references that are promoted to shared_ptr when Signal is
|
|
|
|
// accessed.
|
|
|
|
std::array<shared,4> c = {
|
|
|
|
std::make_shared<Connected>(id++),
|
|
|
|
std::make_shared<Connected>(id++),
|
|
|
|
std::make_shared<Connected>(id++),
|
|
|
|
std::make_shared<Connected>(id++),
|
|
|
|
};
|
|
|
|
assert(t.size() == c.size());
|
|
|
|
for (unsigned i = 1; i < c.size(); ++i) {
|
|
|
|
c[0]->connect(out, c[0], c[i], i - 1, dis(rng));
|
|
|
|
c[i]->connect(out, c[i], c[0], 0, dis(rng));
|
|
|
|
}
|
|
|
|
external.connect(out, c[1], 1, dis(rng));
|
|
|
|
auto thr = [&out](shared c) {
|
|
|
|
TRACE(command, out) << "Thread " << c->id << " started." << std::endl;
|
|
|
|
weak ref = c;
|
|
|
|
for (;c->caller < c->count; ++c->caller) {
|
2019-06-01 15:30:26 -06:00
|
|
|
c->signal(std::move(c->caller));
|
2018-07-02 09:48:33 -06:00
|
|
|
}
|
|
|
|
TRACE(command, out) << "Thread " << c->id << " resets shared." << std::endl;
|
|
|
|
c.reset();
|
|
|
|
while((c = ref.lock())) {
|
|
|
|
++c->caller;
|
2019-06-01 15:30:26 -06:00
|
|
|
c->signal(std::move(c->caller));
|
2018-07-02 09:48:33 -06:00
|
|
|
c.reset();
|
|
|
|
std::this_thread::sleep_for(delay*25);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
for (unsigned i = 0; i < c.size(); ++i) {
|
|
|
|
TRACE(command, out) << "start thread " << i << std::endl;
|
|
|
|
t[i] = std::thread{thr, c[i]};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TRACE(command, out) << "running " << std::endl;
|
|
|
|
for (;external->caller < external->count; ++external->caller) {
|
2019-06-01 15:30:26 -06:00
|
|
|
external->signal(std::move(external->caller));
|
2018-07-02 09:48:33 -06:00
|
|
|
external->reconnect(1);
|
|
|
|
}
|
|
|
|
TRACE(command, out) << "join " << std::endl;
|
|
|
|
for (unsigned i = 0; i < t.size(); ++i)
|
|
|
|
t[i].join();
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2015-04-01 15:02:33 -06:00
|
|
|
if (parameters.size() >= 1)
|
|
|
|
{
|
|
|
|
if (parameters[0] == "stop")
|
|
|
|
{
|
|
|
|
shutdown_flag = true;
|
|
|
|
while(!final_flag)
|
|
|
|
{
|
|
|
|
Core::getInstance().getConsole().msleep(60);
|
|
|
|
}
|
|
|
|
shutdown_flag = false;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
2011-06-24 21:35:29 -06:00
|
|
|
final_flag = false;
|
2015-04-01 15:02:33 -06:00
|
|
|
if (!out.is_console())
|
|
|
|
return CR_FAILURE;
|
2012-03-10 06:25:00 -07:00
|
|
|
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
|
|
|
|
};
|
2021-09-06 23:16:21 -06:00
|
|
|
const char VARIABLE_IS_NOT_USED * kittenz1 []=
|
2011-06-19 20:29:38 -06:00
|
|
|
{
|
|
|
|
" ____",
|
|
|
|
" (. \\",
|
|
|
|
" \\ | ",
|
|
|
|
" \\ |___(\\--/)",
|
|
|
|
" __/ ( . . )",
|
|
|
|
" \"'._. '-.O.'",
|
|
|
|
" '-. \\ \"|\\",
|
|
|
|
" '.,,/'.,,mrf",
|
|
|
|
0
|
|
|
|
};
|
2011-07-14 03:15:23 -06:00
|
|
|
con.cursor(false);
|
|
|
|
con.clear();
|
2012-08-18 23:21:25 -06:00
|
|
|
Console::color_value color = COLOR_BLUE;
|
2011-06-19 20:29:38 -06:00
|
|
|
while(1)
|
|
|
|
{
|
2018-06-30 12:10:51 -06:00
|
|
|
if(shutdown_flag || !con.isInited())
|
2011-06-24 21:35:29 -06:00
|
|
|
{
|
|
|
|
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);
|
2018-06-01 08:02:05 -06:00
|
|
|
color = Console::color_value(int(color) + 1);
|
2012-08-18 23:21:25 -06:00
|
|
|
if(color > COLOR_MAX)
|
|
|
|
color = COLOR_BLUE;
|
2011-06-19 20:29:38 -06:00
|
|
|
}
|
|
|
|
}
|