Skip to content

Commit 38140fb

Browse files
committed
Copy engravings in RFR, and update the art image function.
1 parent c8747a7 commit 38140fb

5 files changed

Lines changed: 123 additions & 38 deletions

File tree

library/xml

plugins/proto/RemoteFortressReader.proto

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ message BlockList
434434
repeated MapBlock map_blocks = 1;
435435
optional int32 map_x = 2;
436436
optional int32 map_y = 3;
437+
repeated Engraving engravings = 4;
437438
}
438439

439440
message PlantDef
@@ -938,4 +939,22 @@ message ArtImage
938939
{
939940
repeated ArtImageElement elements = 1;
940941
optional MatPair id = 2;
941-
}
942+
}
943+
944+
message Engraving
945+
{
946+
optional Coord pos = 1;
947+
optional int32 quality = 2;
948+
optional int32 tile = 3;
949+
optional ArtImage image = 4;
950+
optional bool floor = 5;
951+
optional bool west = 6;
952+
optional bool east = 7;
953+
optional bool north = 8;
954+
optional bool south = 9;
955+
optional bool hidden = 10;
956+
optional bool northwest = 11;
957+
optional bool northeast = 12;
958+
optional bool southwest = 13;
959+
optional bool southeast = 14;
960+
}

plugins/remotefortressreader/item_reader.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,6 @@ void CopyImage(const df::art_image * image, ArtImage * netImage)
107107
}
108108
}
109109

110-
void CopyImage(df::art_image_ref imageRef, ArtImage * netImage)
111-
{
112-
{
113-
for (int i = 0; i < world->art_image_chunks.size(); i++)
114-
{
115-
auto chunk = world->art_image_chunks[i];
116-
if (chunk->id != imageRef.id)
117-
continue;
118-
auto image = chunk->images[imageRef.subid];
119-
CopyImage(image, netImage);
120-
}
121-
}
122-
}
123-
124110
void CopyItem(RemoteFortressReader::Item * NetItem, df::item * DfItem)
125111
{
126112
NetItem->set_id(DfItem->id);
@@ -196,7 +182,27 @@ void CopyItem(RemoteFortressReader::Item * NetItem, df::item * DfItem)
196182
case df::enums::item_type::STATUE:
197183
{
198184
VIRTUAL_CAST_VAR(statue, df::item_statuest, DfItem);
199-
CopyImage(statue->image, NetItem->mutable_image());
185+
186+
df::art_image_chunk * chunk = NULL;
187+
GET_ART_IMAGE_CHUNK GetArtImageChunk = reinterpret_cast<GET_ART_IMAGE_CHUNK>(Core::getInstance().vinfo->getAddress("rfr_get_art_image"));
188+
if (GetArtImageChunk)
189+
{
190+
chunk = GetArtImageChunk(&(world->art_image_chunks), statue->image.id);
191+
}
192+
else
193+
{
194+
for (int i = 0; i < world->art_image_chunks.size(); i++)
195+
{
196+
if (world->art_image_chunks[i]->id == statue->image.id)
197+
chunk = world->art_image_chunks[i];
198+
}
199+
}
200+
if (chunk)
201+
{
202+
CopyImage(chunk->images[statue->image.subid], NetItem->mutable_image());
203+
}
204+
205+
200206
break;
201207
}
202208
case df::enums::item_type::CORPSE:

plugins/remotefortressreader/item_reader.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace df
1212
struct item;
1313
struct map_block;
1414
struct art_image;
15-
struct art_image_ref;
15+
struct art_image_chunk;
1616
struct world;
1717
}
1818

@@ -25,11 +25,8 @@ DFHack::command_result GetItemList(DFHack::color_ostream &stream, const DFHack::
2525
void CopyItem(RemoteFortressReader::Item * NetItem, df::item * DfItem);
2626
void ConvertDFColorDescriptor(int16_t index, RemoteFortressReader::ColorDefinition * out);
2727

28-
#if(defined(WIN32) && !defined(_WIN64))
29-
typedef df::art_image * (__thiscall *GET_IMAGE)(df::world *, df::art_image_ref *, int16_t *);
30-
#else
31-
typedef df::art_image * (*GET_IMAGE)(df::world *, df::art_image_ref *, int16_t *);
32-
#endif
28+
typedef df::art_image_chunk * (*GET_ART_IMAGE_CHUNK)(std::vector<df::art_image_chunk* > *, int);
3329

30+
void CopyImage(const df::art_image * image, RemoteFortressReader::ArtImage * netImage);
3431

3532
#endif // !ITEM_READER_H

plugins/remotefortressreader/remotefortressreader.cpp

Lines changed: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "df/descriptor_shape.h"
5858
#include "df/dfhack_material_category.h"
5959
#include "df/enabler.h"
60+
#include "df/engraving.h"
6061
#include "df/graphic.h"
6162
#include "df/historical_figure.h"
6263

@@ -182,20 +183,18 @@ const char* growth_locations[] = {
182183
#include "df/art_image.h"
183184
#include "df/art_image_chunk.h"
184185
#include "df/art_image_ref.h"
185-
command_result generate_image(color_ostream &out, vector <string> & parameters)
186+
command_result loadArtImageChunk(color_ostream &out, vector <string> & parameters)
186187
{
187-
df::art_image_ref imageRef;
188-
imageRef.civ_id = -1;
189-
imageRef.id = -1;
190-
imageRef.site_id = -1;
191-
imageRef.subid = -1;
188+
if (parameters.size() != 1)
189+
return CR_WRONG_USAGE;
192190

193-
GET_IMAGE getImage = reinterpret_cast<GET_IMAGE>(Core::getInstance().vinfo->getAddress("rfr_get_art_image"));
194-
if (getImage)
191+
192+
GET_ART_IMAGE_CHUNK GetArtImageChunk = reinterpret_cast<GET_ART_IMAGE_CHUNK>(Core::getInstance().vinfo->getAddress("rfr_get_art_image"));
193+
if (GetArtImageChunk)
195194
{
196-
int16_t subid = -1;
197-
auto image = getImage(world, &imageRef, &subid);
198-
out.print("Id: %d, subid: %d\n", image->id, image->subid);
195+
int index = atoi(parameters[0].c_str());
196+
auto chunk = GetArtImageChunk(&(world->art_image_chunks), index);
197+
out.print("Loaded chunk id: &d", chunk->id);
199198
}
200199
return CR_OK;
201200
}
@@ -271,10 +270,10 @@ DFhackCExport command_result plugin_init(color_ostream &out, std::vector <Plugin
271270
));
272271
commands.push_back(PluginCommand("RemoteFortressReader_version", "List the loaded RemoteFortressReader version", RemoteFortressReader_version, false, "This is used for plugin version checking."));
273272
commands.push_back(PluginCommand(
274-
"generate_image",
275-
"make a blank art image using inbuilt DF functions.",
276-
generate_image, false,
277-
"used to test the function pointer being correct. If everything works, the subid should increment each time."));
273+
"load_art_image_chunk",
274+
"Gets an art image chunk by index, loading from disk if necessary",
275+
loadArtImageChunk, false,
276+
"Usage: load_art_image_chunk N, where N is the id of the chunk to get."));
278277
enableUpdates = true;
279278
return CR_OK;
280279
}
@@ -799,13 +798,29 @@ bool areItemsChanged(vector<int> * items)
799798
return result;
800799
}
801800

801+
map<int, int> engravingHashes;
802+
803+
bool isEngravingNew(int index)
804+
{
805+
if (engravingHashes[index])
806+
return false;
807+
engravingHashes[index] = true;
808+
return true;
809+
}
810+
811+
void engravingIsNotNew(int index)
812+
{
813+
engravingHashes[index] = false;
814+
}
815+
802816
static command_result ResetMapHashes(color_ostream &stream, const EmptyMessage *in)
803817
{
804818
hashes.clear();
805819
waterHashes.clear();
806820
buildingHashes.clear();
807821
spatterHashes.clear();
808822
itemHashes.clear();
823+
engravingHashes.clear();
809824
return CR_OK;
810825
}
811826

@@ -1485,6 +1500,54 @@ static command_result GetBlockList(color_ostream &stream, const BlockRequest *in
14851500
}
14861501
}
14871502
}
1503+
1504+
for (int i = 0; i < world->engravings.size(); i++)
1505+
{
1506+
auto engraving = world->engravings[i];
1507+
if (engraving->pos.x < (min_x * 16) || engraving->pos.x >(max_x * 16))
1508+
continue;
1509+
if (engraving->pos.y < (min_y * 16) || engraving->pos.x >(max_y * 16))
1510+
continue;
1511+
if (engraving->pos.z < (min_z * 16) || engraving->pos.x >(max_z * 16))
1512+
continue;
1513+
if (!isEngravingNew(i))
1514+
continue;
1515+
1516+
df::art_image_chunk * chunk = NULL;
1517+
GET_ART_IMAGE_CHUNK GetArtImageChunk = reinterpret_cast<GET_ART_IMAGE_CHUNK>(Core::getInstance().vinfo->getAddress("rfr_get_art_image"));
1518+
if (GetArtImageChunk)
1519+
{
1520+
chunk = GetArtImageChunk(&(world->art_image_chunks), engraving->art_id);
1521+
}
1522+
else
1523+
{
1524+
for (int i = 0; i < world->art_image_chunks.size(); i++)
1525+
{
1526+
if (world->art_image_chunks[i]->id == engraving->art_id)
1527+
chunk = world->art_image_chunks[i];
1528+
}
1529+
}
1530+
if (!chunk)
1531+
{
1532+
engravingIsNotNew(i);
1533+
continue;
1534+
}
1535+
auto netEngraving = out->add_engravings();
1536+
ConvertDFCoord(engraving->pos, netEngraving->mutable_pos());
1537+
netEngraving->set_quality(engraving->quality);
1538+
netEngraving->set_tile(engraving->tile);
1539+
CopyImage(chunk->images[engraving->art_subid], netEngraving->mutable_image());
1540+
netEngraving->set_floor(engraving->flags.bits.floor);
1541+
netEngraving->set_west(engraving->flags.bits.west);
1542+
netEngraving->set_east(engraving->flags.bits.east);
1543+
netEngraving->set_north(engraving->flags.bits.north);
1544+
netEngraving->set_south(engraving->flags.bits.south);
1545+
netEngraving->set_hidden(engraving->flags.bits.hidden);
1546+
netEngraving->set_northwest(engraving->flags.bits.northwest);
1547+
netEngraving->set_northeast(engraving->flags.bits.northeast);
1548+
netEngraving->set_southwest(engraving->flags.bits.southwest);
1549+
netEngraving->set_southeast(engraving->flags.bits.southeast);
1550+
}
14881551
MC.trash();
14891552
return CR_OK;
14901553
}

0 commit comments

Comments
 (0)