@ -8,6 +8,7 @@
# include "df/creature_raw.h"
# include "df/caste_raw.h"
# include "modules/World.h"
# include "MemAccess.h"
//#include "df/world.h"
@ -25,17 +26,17 @@ DFhackCExport command_result plugin_init(color_ostream &out, std::vector <Plugin
{
commands . push_back ( PluginCommand (
" list-generated " ,
" Prints a list of generated creature tokens. Use \" list-generated detailed \" to show descriptions. " ,
" Prints a list of generated creature tokens. " ,
list_creatures ,
false , //allow non-interactive use
" Prints a list of generated creature tokens. Use \" list-generated detailed \" to show descriptions. "
" Use \" list-generated detailed \" to show descriptions. "
) ) ;
commands . push_back ( PluginCommand (
" save-generated-raws " ,
" Saves a graphics raw file to use with the renamed generated creatures. " ,
save_generated_raw ,
false , //allow non-interactive use
" Saves a graphics raw file to use with the renamed generated creature s."
" Creates graphics_procedural_creatures.txt, with a full set of creature graphics definitions for all possible generated beasts. Modify the resulting file to suit your need s."
) ) ; return CR_OK ;
}
@ -98,9 +99,10 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
{
if ( ! is_enabled )
return CR_OK ;
switch ( event )
{
case DFHack : : SC_WORLD_LOADED :
if ( event ! = DFHack : : SC_WORLD_LOADED )
return CR_OK ;
CoreSuspender suspend ;
std : : vector < int > descriptorCount = std : : vector < int > ( descriptors . size ( ) ) ;
@ -111,6 +113,8 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
return CR_OK ;
}
int creatureCount = 0 ;
for ( int i = 0 ; i < world - > raws . creatures . all . size ( ) ; i + + )
{
auto creatureRaw = world - > raws . creatures . all [ i ] ;
@ -165,11 +169,14 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
creatureRaw - > creature_id . append ( " _ " + std : : to_string ( descriptorCount [ foundIndex ] ) ) ;
}
descriptorCount [ foundIndex ] + + ;
creatureCount + + ;
}
version = World : : AddPersistentData ( " AlreadyRenamedCreatures " ) ;
version . ival ( 1 ) = RENAMER_VERSION ;
break ;
}
out < < " Renamed " < < creatureCount < < " generated creatures to have sensible names. " < < endl ;
return CR_OK ;
}
@ -200,10 +207,68 @@ command_result list_creatures(color_ostream &out, std::vector <std::string> & pa
}
out . print ( " \n " ) ;
}
return CR_OK ;
}
command_result save_generated_raw ( color_ostream & out , std : : vector < std : : string > & parameters )
{
# ifdef LINUX_BUILD
std : : string pathSep = " / " ;
# else
std : : string pathSep = " \\ " ;
# endif
int pageWidth = 16 ;
int pageHeight = ( descriptors . size ( ) / pageWidth ) + ( ( descriptors . size ( ) % pageWidth > 0 ) ? 1 : 0 ) ;
int tileWidth = 24 ;
int tileHeight = 24 ;
std : : string fileName = " graphics_procedural_creatures " ;
std : : string pageName = " PROCEDURAL_FRIENDLY " ;
int repeats = 128 ;
std : : ofstream outputFile ( fileName + " .txt " , std : : ios : : out | std : : ios : : trunc ) ;
outputFile < < fileName < < endl < < endl ;
outputFile < < " [OBJECT:GRAPHICS] " < < endl < < endl ;
outputFile < < " [TILE_PAGE: " < < pageName < < " ] " < < endl ;
outputFile < < " [FILE:procedural_friendly.png] " < < endl ;
outputFile < < " [TILE_DIM: " < < tileWidth < < " : " < < tileHeight < < " ] " < < endl ;
outputFile < < " [PAGE_DIM: " < < pageWidth < < " : " < < pageHeight < < " ] " < < endl < < endl ;
for ( size_t descIndex = 0 ; descIndex < descriptors . size ( ) ; descIndex + + )
{
for ( size_t prefIndex = 0 ; prefIndex < prefixes . size ( ) ; prefIndex + + )
{
for ( size_t rep = 0 ; rep < repeats ; rep + + )
{
auto descriptor = descriptors [ descIndex ] ;
for ( int j = 0 ; j < descriptor . size ( ) ; j + + )
{
if ( descriptor [ j ] = = ' ' )
descriptor [ j ] = ' _ ' ;
else
descriptor [ j ] = toupper ( descriptor [ j ] ) ;
}
auto prefix = prefixes [ prefIndex ] ;
if ( prefix [ prefix . length ( ) - 1 ] ! = ' _ ' )
prefix . append ( " _ " ) ;
std : : string token = prefix + descriptor ;
if ( rep > 0 )
token . append ( " _ " + std : : to_string ( rep ) ) ;
outputFile < < " [CREATURE_GRAPHICS: " < < token < < " ] " < < endl ;
outputFile < < " [DEFAULT: " < < pageName < < " : " < < descIndex % pageWidth < < " : " < < descIndex / pageWidth < < " :ADD_COLOR] " < < endl ;
}
outputFile < < endl ;
}
outputFile < < endl ;
}
outputFile . close ( ) ;
return CR_OK ;
}