Skip to content

Commit

Permalink
Attempt at getting dye blending to work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Caldfir authored and Caldfir committed Apr 15, 2012
1 parent bf86bcf commit 953e8d8
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 43 deletions.
39 changes: 21 additions & 18 deletions Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Worn_Item::Worn_Item()
{
matt.index = -1;
matt.type = -1;
dyed = 0;
dyematt.index = -1;
dyematt.type = -1;
}

Block::Block(WorldSegment* ownerSegment)
Expand Down Expand Up @@ -66,9 +67,10 @@ Block::Block(WorldSegment* ownerSegment)
visible = true;

Item.item.type =-1;
Item.dyed = 0;
Item.matt.type=-1;
Item.matt.index=-1;
Item.dyematt.type=-1;
Item.dyematt.index=-1;
}


Expand Down Expand Up @@ -230,7 +232,7 @@ void Block::Draw()
//fixme: needs to be scaled
if(Eff_SeaFoam.density > 0)
{
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_SeaFoam.matt.type, Eff_SeaFoam.matt.index);
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_SeaFoam.matt);
tint.a*=Eff_SeaFoam.density/100.0f;
al_draw_tinted_bitmap(sprite_oceanwave,tint, drawx, drawy - (WALLHEIGHT), 0);
}
Expand Down Expand Up @@ -304,7 +306,7 @@ void Block::Draw()
contentLoader->itemConfigs[Item.item.type]->default_sprite.draw_world(x, y, z, this);
}
else
DrawSpriteFromSheet( 350, IMGObjectSheet, lookupMaterialColor(Item.matt.type, Item.matt.index, Item.dyed), drawx, (tileShapeBasic==tiletype_shape_basic::Ramp)?(drawy - ((WALLHEIGHT/2)*config.scale)):drawy , this);
DrawSpriteFromSheet( 350, IMGObjectSheet, lookupMaterialColor(Item.matt, Item.dyematt), drawx, (tileShapeBasic==tiletype_shape_basic::Ramp)?(drawy - ((WALLHEIGHT/2)*config.scale)):drawy , this);
}


Expand Down Expand Up @@ -455,44 +457,44 @@ void Block::Draw()

if(Eff_Web.density > 0)
{
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Web.matt.type, Eff_Web.matt.index);
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Web.matt);
tint.a*=Eff_Web.density/100.0f;
DrawSpriteFromSheet(rando%5, sprite_webing, tint, drawx, drawy, this, 4.0f);
//al_draw_tinted_bitmap(sprite_webing,tint, drawx, drawy - (WALLHEIGHT), 0);
}
if(Eff_Miasma.density > 0)
{
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Miasma.matt.type, Eff_Miasma.matt.index);
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Miasma.matt);
draw_particle_cloud(Eff_Miasma.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_miasma, tint);
}
if(Eff_Steam.density > 0)
{
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Steam.matt.type, Eff_Steam.matt.index);
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Steam.matt);
draw_particle_cloud(Eff_Steam.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_water, tint);
}
if(Eff_Mist.density > 0)
{
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Mist.matt.type, Eff_Mist.matt.index);
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Mist.matt);
draw_particle_cloud(Eff_Mist.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_water2, tint);
}
if(Eff_MaterialDust.density > 0)
{
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_MaterialDust.matt.type, Eff_MaterialDust.matt.index);
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_MaterialDust.matt);
draw_particle_cloud(Eff_MaterialDust.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_dust, tint);
}
if(Eff_MagmaMist.density > 0)
{
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_MagmaMist.matt.type, Eff_MagmaMist.matt.index);
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_MagmaMist.matt);
draw_particle_cloud(Eff_MagmaMist.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_magma, tint);
}
if(Eff_Smoke.density > 0)
{
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Smoke.matt.type, Eff_Smoke.matt.index);
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Smoke.matt);
draw_particle_cloud(Eff_Smoke.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_smoke, tint);
}
if(Eff_Dragonfire.density > 0)
{
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Dragonfire.matt.type, Eff_Dragonfire.matt.index);
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Dragonfire.matt);
tint.a*=Eff_Dragonfire.density/100.0f;
tint.g*=Eff_Dragonfire.density/100.0f;
tint.b*=Eff_Dragonfire.density/100.0f;
Expand All @@ -503,7 +505,7 @@ void Block::Draw()
}
if(Eff_Fire.density > 0)
{
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Fire.matt.type, Eff_Fire.matt.index);
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_Fire.matt);
tint.a*=Eff_Fire.density/100.0f;
tint.g*=Eff_Fire.density/100.0f;
tint.b*=Eff_Fire.density/100.0f;
Expand All @@ -514,17 +516,17 @@ void Block::Draw()
}
if(Eff_MaterialGas.density > 0)
{
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_MaterialGas.matt.type, Eff_MaterialGas.matt.index);
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_MaterialGas.matt);
draw_particle_cloud(Eff_MaterialGas.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_boiling, tint);
}
if(Eff_MaterialVapor.density > 0)
{
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_MaterialVapor.matt.type, Eff_MaterialVapor.matt.index);
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_MaterialVapor.matt);
draw_particle_cloud(Eff_MaterialVapor.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_boiling, tint);
}
if(Eff_OceanWave.density > 0)
{
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_OceanWave.matt.type, Eff_OceanWave.matt.index);
ALLEGRO_COLOR tint = lookupMaterialColor(Eff_OceanWave.matt);
draw_particle_cloud(Eff_OceanWave.density, drawx, drawy - (SPRITEHEIGHT/2), SPRITEWIDTH, SPRITEHEIGHT, sprite_water, tint);
}
}
Expand Down Expand Up @@ -598,7 +600,7 @@ void Block::DrawPixel(int drawx, int drawy)
tileShapeBasic==tiletype_shape_basic::Stair
)
{
al_put_pixel(drawx, drawy, lookupMaterialColor(this->material.type, this->material.index));
al_put_pixel(drawx, drawy, lookupMaterialColor(this->material));
}
if(this->water.index)
{
Expand All @@ -614,7 +616,8 @@ void Block::DrawPixel(int drawx, int drawy)
(tileMaterial == tiletype_material::GRASS_DRY) ||
(tileMaterial == tiletype_material::GRASS_DEAD)))
{
temp = lookupMaterialColor(WOOD, grassmat);
DFHack::t_matglossPair woodymat; woodymat.index = WOOD, woodymat.type = grassmat;
temp = lookupMaterialColor(woodymat);
al_draw_pixel(drawx, drawy, al_map_rgba_f(temp.r,temp.g, temp.b, (float)grasslevel/100.0f));
}
}
Expand Down
4 changes: 2 additions & 2 deletions Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct Effect
struct Worn_Item
{
DFHack::t_matglossPair matt;
bool dyed;
DFHack::t_matglossPair dyematt;
int8_t rating;
Worn_Item();
};
Expand Down Expand Up @@ -148,7 +148,7 @@ class Block
{
DFHack::t_matglossPair item;
DFHack::t_matglossPair matt;
bool dyed;
DFHack::t_matglossPair dyematt;
} Item;

//These are actually applied to the creature standing here, but there's only one creature shown, so it's okay.
Expand Down
23 changes: 17 additions & 6 deletions ContentLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,19 @@ void ContentLoader::flushCreatureConfig()
// make big enough to hold all creatures
creatureConfigs.clear();
}
ALLEGRO_COLOR lookupMaterialColor(int matType,int matIndex, bool dye)

ALLEGRO_COLOR lookupMaterialColor(DFHack::t_matglossPair matt)
{
DFHack::t_matglossPair dyematt;
dyematt.index = -1, dyematt.type = -1;
return lookupMaterialColor(matt, dyematt);
}

ALLEGRO_COLOR lookupMaterialColor(DFHack::t_matglossPair matt, DFHack::t_matglossPair dyematt)
{
int matType = (int) matt.type;
int matIndex = (int) matt.index;

if (matType < 0)
{
//This should not normally happen, but if it does, we don't want crashes, so we'll return magic pink so show something's wrong.
Expand All @@ -771,14 +782,14 @@ ALLEGRO_COLOR lookupMaterialColor(int matType,int matIndex, bool dye)
return contentLoader->colorConfigs.at(matType).colorMaterials.at(matIndex).color;
}
DFColor:
MaterialInfo mat;
MaterialInfo mat, dye;
if(mat.decode(matType, matIndex))
{
if(dye)
if(dyematt.type>=0 && dyematt.index>=0 && dye.decode(dyematt.type, dyematt.index))
return al_map_rgb_f(
contentLoader->Mats->color[mat.material->powder_dye].red,
contentLoader->Mats->color[mat.material->powder_dye].green,
contentLoader->Mats->color[mat.material->powder_dye].blue);
contentLoader->Mats->color[dye.material->powder_dye].red * contentLoader->Mats->color[mat.material->state_color[0]].red,
contentLoader->Mats->color[dye.material->powder_dye].green * contentLoader->Mats->color[mat.material->state_color[0]].green,
contentLoader->Mats->color[dye.material->powder_dye].blue * contentLoader->Mats->color[mat.material->state_color[0]].blue);
else
return al_map_rgb_f(
contentLoader->Mats->color[mat.material->state_color[0]].red,
Expand Down
3 changes: 2 additions & 1 deletion ContentLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ uint8_t lookupMaterialFore(int matType,int matIndex);
uint8_t lookupMaterialBack(int matType,int matIndex);
uint8_t lookupMaterialBright(int matType,int matIndex);
const char *lookupTreeName(int matIndex);
ALLEGRO_COLOR lookupMaterialColor(int matType,int matIndex, bool dye = 0);
ALLEGRO_COLOR lookupMaterialColor(DFHack::t_matglossPair matt, DFHack::t_matglossPair dyematt);
ALLEGRO_COLOR lookupMaterialColor(DFHack::t_matglossPair matt);
const char * lookupFormName(int formType);
ShadeBy getShadeType(const char* Input);
5 changes: 2 additions & 3 deletions Creatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,8 @@ void ReadCreaturesToSegment( DFHack::Core& DF, WorldSegment* segment)
auto Improvement_Thread = virtual_cast<df::itemimprovement_threadst>(Constructed_Item->improvements[idex]);
if(!Improvement_Thread)
continue;
equipment.matt.type = Improvement_Thread->dye.mat_type;
equipment.matt.index = Improvement_Thread->dye.mat_index;
equipment.dyed = 1;
equipment.dyematt.type = Improvement_Thread->dye.mat_type;
equipment.dyematt.index = Improvement_Thread->dye.mat_index;
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions MapLoading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,19 +522,17 @@ void ReadCellToSegment(DFHack::Core& DF, WorldSegment& segment, int CellX, int C
if(!Improvement_Thread)
continue;
if (Improvement_Thread->dye.mat_type < 0) break;
b->Item.matt.type = Improvement_Thread->dye.mat_type;
b->Item.matt.index = Improvement_Thread->dye.mat_index;
b->Item.dyed = 1;
b->Item.dyematt.type = Improvement_Thread->dye.mat_type;
b->Item.dyematt.index = Improvement_Thread->dye.mat_index;
}
}
else if (found_item->getType() == item_type::THREAD)
{
auto Thread_Item = virtual_cast<df::item_threadst>(found_item);
if(!Thread_Item) break;
if (Thread_Item->dye_mat_type < 0) break;
b->Item.matt.type = Thread_Item->dye_mat_type;
b->Item.matt.index = Thread_Item->dye_mat_index;
b->Item.dyed = 1;
b->Item.dyematt.type = Thread_Item->dye_mat_type;
b->Item.dyematt.index = Thread_Item->dye_mat_index;
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions SpriteObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,15 +942,16 @@ ALLEGRO_COLOR c_sprite::get_color(void* block)
case ShadeXml:
return shadecolor;
case ShadeMat:
return lookupMaterialColor(b->material.type, b->material.index);
return lookupMaterialColor(b->material);
case ShadeGrass:
return lookupMaterialColor(WOOD, b->grassmat);
DFHack::t_matglossPair woodymat; woodymat.index = WOOD, woodymat.type = b->grassmat;
return lookupMaterialColor(woodymat);
case ShadeBuilding:
return lookupMaterialColor(b->building.info.material.type, b->building.info.material.index);
return lookupMaterialColor(b->building.info.material);
case ShadeLayer:
return lookupMaterialColor(b->layerMaterial.type, b->layerMaterial.index);
return lookupMaterialColor(b->layerMaterial);
case ShadeVein:
return lookupMaterialColor(b->veinMaterial.type, b->veinMaterial.index);
return lookupMaterialColor(b->veinMaterial);
case ShadeMatFore:
return config.colors.getDfColor(lookupMaterialFore(b->material.type, b->material.index), lookupMaterialBright(b->material.type, b->material.index));
case ShadeMatBack:
Expand Down Expand Up @@ -1027,11 +1028,11 @@ ALLEGRO_COLOR c_sprite::get_color(void* block)
return al_map_rgb(255, 255, 0);
if(b->inv->item[itemtype][itemsubtype].empty())
return al_map_rgb(0, 0, 255);
return lookupMaterialColor(b->inv->item[itemtype][itemsubtype][0].matt.type, b->inv->item[itemtype][itemsubtype][0].matt.index, b->inv->item[itemtype][itemsubtype][0].dyed);
return lookupMaterialColor(b->inv->item[itemtype][itemsubtype][0].matt, b->inv->item[itemtype][itemsubtype][0].dyematt);
}
else return al_map_rgb(255,255,255);
case ShadeItem:
return lookupMaterialColor(b->Item.matt.type, b->Item.matt.index, b->Item.dyed);
return lookupMaterialColor(b->Item.matt, b->Item.dyematt);
default:
return al_map_rgb(255, 255, 255);
} ;
Expand Down
Binary file modified resources/creatures/large_256/Thumbs.db
Binary file not shown.

0 comments on commit 953e8d8

Please sign in to comment.