|
|
@ -26,149 +26,149 @@ DFHACK_PLUGIN("misery");
|
|
|
|
command_result misery(color_ostream& out, vector<string>& parameters);
|
|
|
|
command_result misery(color_ostream& out, vector<string>& parameters);
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown(color_ostream& out) {
|
|
|
|
DFhackCExport command_result plugin_shutdown(color_ostream& out) {
|
|
|
|
factor = 1;
|
|
|
|
factor = 1;
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_onupdate(color_ostream& out) {
|
|
|
|
DFhackCExport command_result plugin_onupdate(color_ostream& out) {
|
|
|
|
static bool wasLoaded = false;
|
|
|
|
static bool wasLoaded = false;
|
|
|
|
if ( factor == 1 || !df::global::world || !df::global::world->map.block_index ) {
|
|
|
|
if ( factor == 1 || !df::global::world || !df::global::world->map.block_index ) {
|
|
|
|
if ( wasLoaded ) {
|
|
|
|
if ( wasLoaded ) {
|
|
|
|
//we just unloaded the game: clear all data
|
|
|
|
//we just unloaded the game: clear all data
|
|
|
|
factor = 1;
|
|
|
|
factor = 1;
|
|
|
|
processedThoughtCountTable.clear();
|
|
|
|
processedThoughtCountTable.clear();
|
|
|
|
fakeThoughts.clear();
|
|
|
|
fakeThoughts.clear();
|
|
|
|
wasLoaded = false;
|
|
|
|
wasLoaded = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( !wasLoaded ) {
|
|
|
|
if ( !wasLoaded ) {
|
|
|
|
wasLoaded = true;
|
|
|
|
wasLoaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t race_id = df::global::ui->race_id;
|
|
|
|
int32_t race_id = df::global::ui->race_id;
|
|
|
|
int32_t civ_id = df::global::ui->civ_id;
|
|
|
|
int32_t civ_id = df::global::ui->civ_id;
|
|
|
|
for ( size_t a = 0; a < df::global::world->units.all.size(); a++ ) {
|
|
|
|
for ( size_t a = 0; a < df::global::world->units.all.size(); a++ ) {
|
|
|
|
df::unit* unit = df::global::world->units.all[a]; //TODO: consider units.active
|
|
|
|
df::unit* unit = df::global::world->units.all[a]; //TODO: consider units.active
|
|
|
|
//living, native units only
|
|
|
|
//living, native units only
|
|
|
|
if ( unit->race != race_id || unit->civ_id != civ_id )
|
|
|
|
if ( unit->race != race_id || unit->civ_id != civ_id )
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
if ( unit->flags1.bits.dead )
|
|
|
|
if ( unit->flags1.bits.dead )
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
int processedThoughtCount;
|
|
|
|
int processedThoughtCount;
|
|
|
|
map<int,int>::iterator i = processedThoughtCountTable.find(unit->id);
|
|
|
|
map<int,int>::iterator i = processedThoughtCountTable.find(unit->id);
|
|
|
|
if ( i == processedThoughtCountTable.end() ) {
|
|
|
|
if ( i == processedThoughtCountTable.end() ) {
|
|
|
|
processedThoughtCount = unit->status.recent_events.size();
|
|
|
|
processedThoughtCount = unit->status.recent_events.size();
|
|
|
|
processedThoughtCountTable[unit->id] = processedThoughtCount;
|
|
|
|
processedThoughtCountTable[unit->id] = processedThoughtCount;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
processedThoughtCount = (*i).second;
|
|
|
|
processedThoughtCount = (*i).second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( processedThoughtCount == unit->status.recent_events.size() ) {
|
|
|
|
if ( processedThoughtCount == unit->status.recent_events.size() ) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
} else if ( processedThoughtCount > unit->status.recent_events.size() ) {
|
|
|
|
} else if ( processedThoughtCount > unit->status.recent_events.size() ) {
|
|
|
|
processedThoughtCount = unit->status.recent_events.size();
|
|
|
|
processedThoughtCount = unit->status.recent_events.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//don't reprocess any old thoughts
|
|
|
|
//don't reprocess any old thoughts
|
|
|
|
vector<df::unit_thought*> newThoughts;
|
|
|
|
vector<df::unit_thought*> newThoughts;
|
|
|
|
for ( size_t b = processedThoughtCount; b < unit->status.recent_events.size(); b++ ) {
|
|
|
|
for ( size_t b = processedThoughtCount; b < unit->status.recent_events.size(); b++ ) {
|
|
|
|
df::unit_thought* oldThought = unit->status.recent_events[b];
|
|
|
|
df::unit_thought* oldThought = unit->status.recent_events[b];
|
|
|
|
const char* bob = ENUM_ATTR(unit_thought_type, value, oldThought->type);
|
|
|
|
const char* bob = ENUM_ATTR(unit_thought_type, value, oldThought->type);
|
|
|
|
if ( bob[0] != '-' ) {
|
|
|
|
if ( bob[0] != '-' ) {
|
|
|
|
//out.print("unit %4d: old thought value = %s\n", unit->id, bob);
|
|
|
|
//out.print("unit %4d: old thought value = %s\n", unit->id, bob);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*out.print("unit %4d: Duplicating thought type %d (%s), value %s, age %d, subtype %d, severity %d\n",
|
|
|
|
/*out.print("unit %4d: Duplicating thought type %d (%s), value %s, age %d, subtype %d, severity %d\n",
|
|
|
|
unit->id,
|
|
|
|
unit->id,
|
|
|
|
oldThought->type.value,
|
|
|
|
oldThought->type.value,
|
|
|
|
ENUM_ATTR(unit_thought_type, caption, (oldThought->type)),
|
|
|
|
ENUM_ATTR(unit_thought_type, caption, (oldThought->type)),
|
|
|
|
//df::enum_traits<df::unit_thought_type>::attr_table[oldThought->type].caption
|
|
|
|
//df::enum_traits<df::unit_thought_type>::attr_table[oldThought->type].caption
|
|
|
|
bob,
|
|
|
|
bob,
|
|
|
|
oldThought->age,
|
|
|
|
oldThought->age,
|
|
|
|
oldThought->subtype,
|
|
|
|
oldThought->subtype,
|
|
|
|
oldThought->severity
|
|
|
|
oldThought->severity
|
|
|
|
);*/
|
|
|
|
);*/
|
|
|
|
//add duplicate thoughts to the temp list
|
|
|
|
//add duplicate thoughts to the temp list
|
|
|
|
for ( size_t c = 0; c < factor; c++ ) {
|
|
|
|
for ( size_t c = 0; c < factor; c++ ) {
|
|
|
|
df::unit_thought* thought = new df::unit_thought;
|
|
|
|
df::unit_thought* thought = new df::unit_thought;
|
|
|
|
thought->type = unit->status.recent_events[b]->type;
|
|
|
|
thought->type = unit->status.recent_events[b]->type;
|
|
|
|
thought->age = unit->status.recent_events[b]->age;
|
|
|
|
thought->age = unit->status.recent_events[b]->age;
|
|
|
|
thought->subtype = unit->status.recent_events[b]->subtype;
|
|
|
|
thought->subtype = unit->status.recent_events[b]->subtype;
|
|
|
|
thought->severity = unit->status.recent_events[b]->severity;
|
|
|
|
thought->severity = unit->status.recent_events[b]->severity;
|
|
|
|
newThoughts.push_back(thought);
|
|
|
|
newThoughts.push_back(thought);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for ( size_t b = 0; b < newThoughts.size(); b++ ) {
|
|
|
|
for ( size_t b = 0; b < newThoughts.size(); b++ ) {
|
|
|
|
fakeThoughts.push_back(std::pair<int, int>(a, unit->status.recent_events.size()));
|
|
|
|
fakeThoughts.push_back(std::pair<int, int>(a, unit->status.recent_events.size()));
|
|
|
|
unit->status.recent_events.push_back(newThoughts[b]);
|
|
|
|
unit->status.recent_events.push_back(newThoughts[b]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
processedThoughtCountTable[unit->id] = unit->status.recent_events.size();
|
|
|
|
processedThoughtCountTable[unit->id] = unit->status.recent_events.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init(color_ostream& out, vector<PluginCommand> &commands) {
|
|
|
|
DFhackCExport command_result plugin_init(color_ostream& out, vector<PluginCommand> &commands) {
|
|
|
|
commands.push_back(PluginCommand("misery", "increase the intensity of negative dwarven thoughts",
|
|
|
|
commands.push_back(PluginCommand("misery", "increase the intensity of negative dwarven thoughts",
|
|
|
|
&misery, false,
|
|
|
|
&misery, false,
|
|
|
|
"misery: When enabled, every new negative dwarven thought will be multiplied by a factor (2 by default).\n"
|
|
|
|
"misery: When enabled, every new negative dwarven thought will be multiplied by a factor (2 by default).\n"
|
|
|
|
"Usage:\n"
|
|
|
|
"Usage:\n"
|
|
|
|
" misery enable n\n"
|
|
|
|
" misery enable n\n"
|
|
|
|
" enable misery with optional magnitude n. If specified, n must be positive.\n"
|
|
|
|
" enable misery with optional magnitude n. If specified, n must be positive.\n"
|
|
|
|
" misery n\n"
|
|
|
|
" misery n\n"
|
|
|
|
" same as \"misery enable n\"\n"
|
|
|
|
" same as \"misery enable n\"\n"
|
|
|
|
" misery enable\n"
|
|
|
|
" misery enable\n"
|
|
|
|
" same as \"misery enable 2\"\n"
|
|
|
|
" same as \"misery enable 2\"\n"
|
|
|
|
" misery disable\n"
|
|
|
|
" misery disable\n"
|
|
|
|
" stop adding new negative thoughts. This will not remove existing duplicated thoughts. Equivalent to \"misery 1\"\n"
|
|
|
|
" stop adding new negative thoughts. This will not remove existing duplicated thoughts. Equivalent to \"misery 1\"\n"
|
|
|
|
" misery clear\n"
|
|
|
|
" misery clear\n"
|
|
|
|
" remove fake thoughts added in this session of DF. Saving makes them permanent! Does not change factor.\n\n"
|
|
|
|
" remove fake thoughts added in this session of DF. Saving makes them permanent! Does not change factor.\n\n"
|
|
|
|
));
|
|
|
|
));
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
command_result misery(color_ostream &out, vector<string>& parameters) {
|
|
|
|
command_result misery(color_ostream &out, vector<string>& parameters) {
|
|
|
|
if ( !df::global::world || !df::global::world->map.block_index ) {
|
|
|
|
if ( !df::global::world || !df::global::world->map.block_index ) {
|
|
|
|
out.printerr("misery can only be enabled in fortress mode with a fully-loaded game.\n");
|
|
|
|
out.printerr("misery can only be enabled in fortress mode with a fully-loaded game.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( parameters.size() < 1 || parameters.size() > 2 ) {
|
|
|
|
if ( parameters.size() < 1 || parameters.size() > 2 ) {
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( parameters[0] == "disable" ) {
|
|
|
|
if ( parameters[0] == "disable" ) {
|
|
|
|
if ( parameters.size() > 1 ) {
|
|
|
|
if ( parameters.size() > 1 ) {
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
factor = 1;
|
|
|
|
factor = 1;
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
} else if ( parameters[0] == "enable" ) {
|
|
|
|
} else if ( parameters[0] == "enable" ) {
|
|
|
|
factor = 2;
|
|
|
|
factor = 2;
|
|
|
|
if ( parameters.size() == 2 ) {
|
|
|
|
if ( parameters.size() == 2 ) {
|
|
|
|
factor = atoi(parameters[1].c_str());
|
|
|
|
factor = atoi(parameters[1].c_str());
|
|
|
|
if ( factor < 1 ) {
|
|
|
|
if ( factor < 1 ) {
|
|
|
|
out.printerr("Second argument must be a positive integer.\n");
|
|
|
|
out.printerr("Second argument must be a positive integer.\n");
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ( parameters[0] == "clear" ) {
|
|
|
|
} else if ( parameters[0] == "clear" ) {
|
|
|
|
for ( size_t a = 0; a < fakeThoughts.size(); a++ ) {
|
|
|
|
for ( size_t a = 0; a < fakeThoughts.size(); a++ ) {
|
|
|
|
int dorfIndex = fakeThoughts[a].first;
|
|
|
|
int dorfIndex = fakeThoughts[a].first;
|
|
|
|
int thoughtIndex = fakeThoughts[a].second;
|
|
|
|
int thoughtIndex = fakeThoughts[a].second;
|
|
|
|
df::global::world->units.all[dorfIndex]->status.recent_events[thoughtIndex]->age = 1000000;
|
|
|
|
df::global::world->units.all[dorfIndex]->status.recent_events[thoughtIndex]->age = 1000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fakeThoughts.clear();
|
|
|
|
fakeThoughts.clear();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
int a = atoi(parameters[0].c_str());
|
|
|
|
int a = atoi(parameters[0].c_str());
|
|
|
|
if ( a < 1 ) {
|
|
|
|
if ( a < 1 ) {
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
factor = a;
|
|
|
|
factor = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|