Skip to content

Commit

Permalink
Added support for tree growths.
Browse files Browse the repository at this point in the history
  • Loading branch information
RosaryMala committed Aug 8, 2014
1 parent d1b5cb0 commit 6ecbe21
Show file tree
Hide file tree
Showing 33 changed files with 1,341 additions and 71 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ SET(PROJECT_SRCS
SpriteColors.cpp
SpriteMaps.cpp
SpriteObjects.cpp
TreeGrowthConfiguration.cpp
UserInput.cpp
WorldSegment.cpp
VegetationConfiguration.cpp
Expand Down Expand Up @@ -138,6 +139,7 @@ ELSE(UNIX)
allegro_font-static.lib
allegro_image-static.lib
allegro_ttf-static.lib
allegro_color-static.lib
freetype-static.lib
winmm.lib
psapi.lib
Expand Down
1 change: 1 addition & 0 deletions ConnectionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ConnectionState::ConnectionState() {
is_connected = network_client->connect();
if (!is_connected) return;
MaterialListCall.bind(network_client, "GetMaterialList", "RemoteFortressReader");
GrowthListCall.bind(network_client, "GetGrowthList", "RemoteFortressReader");
BlockListCall.bind(network_client, "GetBlockList", "RemoteFortressReader");
HashCheckCall.bind(network_client, "CheckHashes", "RemoteFortressReader");
TiletypeListCall.bind(network_client, "GetTiletypeList", "RemoteFortressReader");
Expand Down
1 change: 1 addition & 0 deletions ConnectionState.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ConnectionState {
RemoteFortressReader::TiletypeList net_tiletype_list;
dfproto::EmptyMessage empty_message;
DFHack::RemoteFunction<dfproto::EmptyMessage, RemoteFortressReader::MaterialList> MaterialListCall;
DFHack::RemoteFunction<dfproto::EmptyMessage, RemoteFortressReader::MaterialList> GrowthListCall;
DFHack::RemoteFunction<RemoteFortressReader::BlockRequest, RemoteFortressReader::BlockList> BlockListCall;
DFHack::RemoteFunction<dfproto::EmptyMessage> HashCheckCall;
DFHack::RemoteFunction<dfproto::EmptyMessage, RemoteFortressReader::TiletypeList> TiletypeListCall;
Expand Down
57 changes: 49 additions & 8 deletions ContentLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "ContentBuildingReader.h"
#include "MapLoading.h"
#include "ColorConfiguration.h"
#include "TreeGrowthConfiguration.h"

#include "tinyxml.h"
#include "GUI.h"
Expand Down Expand Up @@ -53,6 +54,8 @@ ContentLoader::~ContentLoader(void)
flushCreatureConfig();
colorConfigs.clear();
materialColorConfigs.clear();
growthTopConfigs.clear();
growthBottomConfigs.clear();
}

bool ContentLoader::Load()
Expand All @@ -69,6 +72,8 @@ bool ContentLoader::Load()
flushItemConfig(itemConfigs);
colorConfigs.clear();
materialColorConfigs.clear();
growthTopConfigs.clear();
growthBottomConfigs.clear();
flushCreatureConfig();
treeConfigs.clear();
shrubConfigs.clear();
Expand All @@ -81,17 +86,18 @@ bool ContentLoader::Load()
if (connection_state)
{
connection_state->MaterialListCall(&(connection_state->empty_message), &materialNameList);
connection_state->GrowthListCall(&(connection_state->empty_message), &growthNameList);
connection_state->TiletypeListCall(&(connection_state->empty_message), &tiletypeNameList);
connection_state->Disconnect();
}

remove("MatList.csv");
FILE* fp = fopen("MatList.csv", "a");
if (fp) {
fprintf(fp, "#,mat_type,mat_index,id,name,color\n");
fprintf(fp, "#;mat_type;mat_index;id;name;color\n");
for (int i = 0; i < materialNameList.material_list_size(); i++)
{
fprintf(fp, "%d,%d,%d,%s,%s,#%02X%02X%02X\n",
fprintf(fp, "%d;%d;%d;%s;%s;#%02X%02X%02X\n",
i,
materialNameList.material_list(i).mat_pair().mat_type(),
materialNameList.material_list(i).mat_pair().mat_index(),
Expand All @@ -101,16 +107,34 @@ bool ContentLoader::Load()
materialNameList.material_list(i).state_color().green(),
materialNameList.material_list(i).state_color().blue());
}
fclose(fp);
fclose(fp);
}
remove("GrowthList.csv");
fp = fopen("GrowthList.csv", "a");
if (fp) {
fprintf(fp, "#;mat_type;mat_index;id;name;color\n");
for (int i = 0; i < growthNameList.material_list_size(); i++)
{
fprintf(fp, "%d;%d;%d;%s;%s;#%02X%02X%02X\n",
i,
growthNameList.material_list(i).mat_pair().mat_type(),
growthNameList.material_list(i).mat_pair().mat_index(),
growthNameList.material_list(i).id().c_str(),
growthNameList.material_list(i).name().c_str(),
growthNameList.material_list(i).state_color().red(),
growthNameList.material_list(i).state_color().green(),
growthNameList.material_list(i).state_color().blue());
}
fclose(fp);
}

remove("TiletypeList.csv");
fp = fopen("TiletypeList.csv", "a");
if (fp) {
fprintf(fp, "id,name,shape,special,material,variant\n");
fprintf(fp, "id;name;shape;special;material;variant\n");
for (int i = 0; i < tiletypeNameList.tiletype_list_size(); i++)
{
fprintf(fp, "%d,%s,%s,%s,%s,%s\n",
fprintf(fp, "%d;%s;%s;%s;%s;%s\n",
tiletypeNameList.tiletype_list(i).id(),
tiletypeNameList.tiletype_list(i).name().c_str(),
TiletypeShapeToString(tiletypeNameList.tiletype_list(i).shape()),
Expand Down Expand Up @@ -296,6 +320,8 @@ bool ContentLoader::reload_configs()
flushItemConfig(itemConfigs);
colorConfigs.clear();
materialColorConfigs.clear();
growthTopConfigs.clear();
growthBottomConfigs.clear();
creatureConfigs.clear();
treeConfigs.clear();
shrubConfigs.clear();
Expand Down Expand Up @@ -446,7 +472,11 @@ bool ContentLoader::parseContentXMLFile( const char* filepath )
runningResult &= parseFluidContent( elemRoot );
} else if( elementType.compare( "items" ) == 0 ) {
runningResult &= parseItemContent( elemRoot );
} else {
}
else if (elementType.compare("growths") == 0) {
runningResult &= parseGrowthContent(elemRoot);
}
else {
contentError("Unrecognised root element",elemRoot);
}

Expand Down Expand Up @@ -487,6 +517,11 @@ bool ContentLoader::parseTerrainContent(TiXmlElement* elemRoot )
return addSingleTerrainConfig( elemRoot );
}

bool ContentLoader::parseGrowthContent(TiXmlElement* elemRoot)
{
return addSingleGrowthConfig(elemRoot);
}

bool ContentLoader::parseColorContent(TiXmlElement* elemRoot )
{
return addSingleColorConfig( elemRoot );
Expand Down Expand Up @@ -1012,8 +1047,14 @@ ShadeBy getShadeType(const char* Input)
if( strcmp(Input, "equipment") == 0) {
return ShadeEquip;
}
if( strcmp(Input, "item") == 0) {
if (strcmp(Input, "item") == 0) {
return ShadeItem;
}
if (strcmp(Input, "wood") == 0) {
return ShadeWood;
}
if (strcmp(Input, "growth") == 0) {
return ShadeGrowth;
}
return ShadeNone;
}
}
4 changes: 4 additions & 0 deletions ContentLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ContentLoader
bool parseBuildingContent( TiXmlElement* elemRoot );
bool parseCreatureContent( TiXmlElement* elemRoot );
bool parseTerrainContent ( TiXmlElement* elemRoot );
bool parseGrowthContent(TiXmlElement* elemRoot);
bool parseTreeContent( TiXmlElement* elemRoot );
bool parseShrubContent( TiXmlElement* elemRoot );
bool parseColorContent( TiXmlElement* elemRoot );
Expand Down Expand Up @@ -46,6 +47,8 @@ class ContentLoader
std::vector<TerrainConfiguration*> terrainWallConfigs;
std::vector<ColorConfiguration> colorConfigs;
MaterialMatcher<ALLEGRO_COLOR> materialColorConfigs;
MaterialMatcher<c_sprite> growthTopConfigs;
MaterialMatcher<c_sprite> growthBottomConfigs;
std::vector<ItemConfiguration*> itemConfigs;
FluidConfiguration lava[8];
FluidConfiguration water[8];
Expand All @@ -55,6 +58,7 @@ class ContentLoader
std::vector<std::vector<int32_t>*> position_Indices;

RemoteFortressReader::MaterialList materialNameList;
RemoteFortressReader::MaterialList growthNameList;
RemoteFortressReader::TiletypeList tiletypeNameList;
std::vector<std::string> professionStrings;
std::map <uint32_t, std::string> custom_workshop_types;
Expand Down
60 changes: 57 additions & 3 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ using namespace std;
#include "df/viewscreen_dungeon_wrestlest.h"
#include "df/ui_advmode.h"
#include "df/report.h"
#include "allegro5/allegro_color.h"
extern ALLEGRO_FONT *font;

int MiniMapTopLeftX = 0;
Expand Down Expand Up @@ -532,7 +533,9 @@ void drawDebugInfo(WorldSegment * segment)
}
int ttype;
const char* tform = NULL;
if (b->tileShapeBasic()==tiletype_shape_basic::Floor) {
draw_textf_border(font, uiColor(1), 2, (i++*al_get_font_line_height(font)), 0,
"Tile: %s", contentLoader->tiletypeNameList.tiletype_list(b->tileType).name().c_str());
if (b->tileShapeBasic() == tiletype_shape_basic::Floor) {
ttype=b->tileType;
tform="floor";
} else if (b->tileShapeBasic()==tiletype_shape_basic::Wall) {
Expand Down Expand Up @@ -794,9 +797,21 @@ void drawDebugInfo(WorldSegment * segment)
if(b->designation.bits.flow_size > 0 || b->tree.index != 0)
draw_textf_border(font, uiColor(1), 2, (i++*al_get_font_line_height(font)), 0,
"tree:%i water:%i,%i", b->tree.index, b->designation.bits.liquid_type, b->designation.bits.flow_size);
if(b->tree.index != 0)
if (b->tree.index != 0)
{
draw_textf_border(font, uiColor(1), 2, (i++*al_get_font_line_height(font)), 0,
"tree name:%s type:%i", lookupTreeName(b->tree.index), b->tree.type);
draw_textf_border(font, uiColor(1), 2, (i++*al_get_font_line_height(font)), 0,
"tree name:%s type:%i", lookupTreeName(b->tree.index), b->tree.type);
"tree tile:%s%s%s%s%s%s%s",
b->tree_tile.bits.trunk ? " trunk" : "",
b->tree_tile.bits.thick_branches_1 ? " thick_branches_1" : "",
b->tree_tile.bits.thick_branches_2 ? " thick_branches_2" : "",
b->tree_tile.bits.thick_branches_3 ? " thick_branches_3" : "",
b->tree_tile.bits.thick_branches_4 ? " thick_branches_4" : "",
b->tree_tile.bits.branches ? " branches" : "",
b->tree_tile.bits.twigs ? " twigs" : ""
);
}
if(b->building.sprites.size() != 0)
draw_textf_border(font, uiColor(1), 2, (i++*al_get_font_line_height(font)), 0,
"%i extra sprites.", b->building.sprites.size());
Expand Down Expand Up @@ -985,6 +1000,19 @@ ALLEGRO_BITMAP * CreateSpriteFromSheet( int spriteNum, ALLEGRO_BITMAP* spriteShe
return al_create_sub_bitmap(spriteSheet, sheetx * SPRITEWIDTH, sheety * SPRITEHEIGHT, SPRITEWIDTH, SPRITEHEIGHT);
}

void DrawMaterialOverlay(int x, int y, int start, int count)
{
int end = start + count;
if (end > contentLoader->materialNameList.material_list_size())
end = contentLoader->materialNameList.material_list_size();
ALLEGRO_BITMAP * target = al_get_target_bitmap();

for (int i = start; i < end; i++)
{
draw_textf_border(font, uiColor(1), x + 5, y*al_get_font_line_height(font), 0, "%s", contentLoader->materialNameList.material_list(i).id().c_str());
}
}

void DrawSpriteIndexOverlay(int imageIndex)
{
ALLEGRO_BITMAP* currentImage;
Expand Down Expand Up @@ -1623,3 +1651,29 @@ void saveMegashot(bool tall)

map_segment.unlockRead();
}

ALLEGRO_COLOR morph_color(ALLEGRO_COLOR source, ALLEGRO_COLOR reference, ALLEGRO_COLOR target)
{
float sH, sS, sL, rH, rS, rL, tH, tS, tL;
al_color_rgb_to_hsv(source.r, source.g, source.b, &sH, &sS, &sL);
al_color_rgb_to_hsv(reference.r, reference.g, reference.b, &rH, &rS, &rL);
al_color_rgb_to_hsv(target.r, target.g, target.b, &tH, &tS, &tL);

sH += tH - rH;
sS += tS - rS;
sL += tL - rL;
if (sH > 360.0f)
sH -= 360.0f;
if (sH < 0.0f)
sH += 360.0f;
if (sS > 1.0f)
sS = 1.0f;
if (sS < 0.0f)
sS = 0.0f;
if (sL > 1.0f)
sL = 1.0f;
if (sL < 0.0f)
sL = 0.0f;

return al_color_hsv(sH, sS, sL);
}
4 changes: 3 additions & 1 deletion GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ extern ALLEGRO_BITMAP* IMGLetterSheet;

extern vector<string*> IMGFilenames;

void swapSegments(void);
void swapSegments(void);

ALLEGRO_COLOR morph_color(ALLEGRO_COLOR source, ALLEGRO_COLOR reference, ALLEGRO_COLOR target);
4 changes: 3 additions & 1 deletion MapLoading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ void readBlockToSegment(DFHack::Core& DF, WorldSegment& segment,
//open terrain needs to be included to make blackboxes if
// we are shading but not showing hidden tiles
if(isOpenTerrain(trueBlock->tiletype[lx][ly])
&& trueBlock->tiletype[lx][ly] != tiletype::RampTop) {
&& trueBlock->tiletype[lx][ly] != tiletype::RampTop
&& tileShape(trueBlock->tiletype[lx][ly]) != tiletype_shape::TWIG) {
if(!ssConfig.show_hidden_tiles
&& ssConfig.shade_hidden_tiles
&& trueBlock->designation[lx][ly].bits.hidden) {
Expand Down Expand Up @@ -717,6 +718,7 @@ void readBlockColumnToSegment(DFHack::Core& DF, WorldSegment& segment,
continue;
t->tree.type = pp->flags.whole;
t->tree.index = pp->material;
t->tree_tile = tile;
if (raw)
{
t->material.type = raw->material_defs.type_basic_mat;
Expand Down
20 changes: 19 additions & 1 deletion SpriteObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1243,8 +1243,17 @@ ALLEGRO_COLOR c_sprite::get_color(void* tile)
return al_map_rgb(255, 255, 255);
case ShadeXml:
return shadecolor;
case ShadeWood:
{
DFHack::t_matglossPair mat = b->material;
if (mat.type == 419) //this is a dirty hack, but it works, at least in vanilla.
mat.type = 420;
return lookupMaterialColor(mat);
}
case ShadeMat:
return lookupMaterialColor(b->material);
case ShadeGrowth:
return growthColor;
case ShadeNamed:
return namedcolor;
case ShadeGrass:
Expand Down Expand Up @@ -1343,4 +1352,13 @@ ALLEGRO_COLOR c_sprite::get_color(void* tile)
return al_map_rgb(255, 255, 255);
} ;
return al_map_rgb(255, 255, 255);
}
}

void c_sprite::set_growthColor(ALLEGRO_COLOR color)
{
growthColor = color;
for (int i = 0; i < subsprites.size(); i++)
{
subsprites[i].set_growthColor(color);
}
}
2 changes: 2 additions & 0 deletions SpriteObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ class c_sprite
int itemtype;
int itemsubtype;
int itemmat;
ALLEGRO_COLOR growthColor;
public:
void set_growthColor(ALLEGRO_COLOR color);
c_sprite(void);
~c_sprite(void);
//void draw_screen(int x, int y);
Expand Down
Loading

0 comments on commit 6ecbe21

Please sign in to comment.