diff options
| author | Petr Mrázek | 2011-08-28 21:00:11 +0200 |
|---|---|---|
| committer | Petr Mrázek | 2011-08-28 21:00:11 +0200 |
| commit | af75c289789a979029cc06e0f00ffd8919c37844 (patch) | |
| tree | a897db8845489e7d28bd122e11df11e72098be2a /SpriteObjects.cpp | |
| parent | 4b56998f191293d9e2122715be85e5f5d221f2f9 (diff) | |
| parent | f0473027a1b1b7d8f62d253c4ed5166070a94af1 (diff) | |
| download | stonesense-af75c289789a979029cc06e0f00ffd8919c37844.tar.gz stonesense-af75c289789a979029cc06e0f00ffd8919c37844.tar.bz2 stonesense-af75c289789a979029cc06e0f00ffd8919c37844.tar.xz | |
Merge branch 'DFAPI'
Diffstat (limited to 'SpriteObjects.cpp')
| -rw-r--r-- | SpriteObjects.cpp | 106 |
1 files changed, 55 insertions, 51 deletions
diff --git a/SpriteObjects.cpp b/SpriteObjects.cpp index dc0075f..35babe1 100644 --- a/SpriteObjects.cpp +++ b/SpriteObjects.cpp @@ -237,6 +237,7 @@ void c_sprite::set_by_xml(TiXmlElement *elemSprite) if (filename != NULL && filename[0] != 0)
{
fileindex = loadConfigImgFile((char*)filename,elemSprite);
+ if(fileindex == -1) return;
}
animframes = getAnimFrames(elemSprite->Attribute("frames"));
@@ -464,7 +465,7 @@ void c_sprite::set_by_xml(TiXmlElement *elemSprite) {
grasstype = INVALID_INDEX;
}
- else grasstype = lookupIndexedType(idstr,contentLoader.organic);
+ else grasstype = lookupIndexedType(idstr,contentLoader->organic);
//Should the sprite be shown only when there is blood?
const char* spritebloodMinStr = elemSprite->Attribute("blood_min");
@@ -540,16 +541,16 @@ void c_sprite::draw_screen(int x, int y) int sheety = sheetindex / SHEET_OBJECTSWIDE;
if(fileindex == -1)
{
-#ifdef _DEBUG
- config.drawcount ++;
-#endif
+ if(config.block_count)
+ config.drawcount ++;
+
al_draw_bitmap_region(IMGObjectSheet, sheetx * spritewidth, sheety * spriteheight, spritewidth, spriteheight, x + offset_x, y + offset_y, 0);
}
else
{
-#ifdef _DEBUG
- config.drawcount ++;
-#endif
+ if(config.block_count)
+ config.drawcount ++;
+
al_draw_bitmap_region(getImgFile(fileindex), sheetx * spritewidth, sheety * spriteheight, spritewidth, spriteheight, x + offset_x, y + (offset_y - WALLHEIGHT), 0);
}
if(!subsprites.empty())
@@ -625,21 +626,19 @@ void c_sprite::draw_world_offset(int x, int y, int z, Block * b, int tileoffset, (grassmin <= b->grasslevel && (grassmax == -1 || grassmax >= b->grasslevel)) &&
((light==LIGHTANY) || ((light==LIGHTYES) && b->designation.bits.skyview) || ((light==LIGHTNO) && !(b->designation.bits.skyview))) &&//only bother with this tile if it's in the light, or not.
((grasstype == -1) || (grasstype == b->grassmat)) &&
- (
- (grass_growth == GRASS_GROWTH_ANY) ||
- (
- (grass_growth == GRASS_GROWTH_NORMAL) &&
- ((tileTypeTable[b->tileType].material == GRASS) || (tileTypeTable[b->tileType].material == GRASS2))
- ) ||
- (
- (grass_growth == GRASS_GROWTH_DRY) &&
- (tileTypeTable[b->tileType].material == GRASS_DRY)
- ) ||
- (
- (grass_growth == GRASS_GROWTH_DEAD) &&
- (tileTypeTable[b->tileType].material == GRASS_DEAD)
- )
- )
+ (
+ (grass_growth == GRASS_GROWTH_ANY) ||
+ (
+ (grass_growth == GRASS_GROWTH_NORMAL) &&
+ ((tileTypeTable[b->tileType].material == GRASS) || (tileTypeTable[b->tileType].material == GRASS2))
+ ) ||
+ (
+ (grass_growth == GRASS_GROWTH_DRY) &&
+ (tileTypeTable[b->tileType].material == GRASS_DRY)
+ ) ||
+ (
+ (grass_growth == GRASS_GROWTH_DEAD) &&
+ (tileTypeTable[b->tileType].material == GRASS_DEAD)
)
{
int32_t drawx = x;
@@ -655,6 +654,9 @@ void c_sprite::draw_world_offset(int x, int y, int z, Block * b, int tileoffset, pointToScreen((int*)&drawx, (int*)&drawy, drawz);
drawx -= TILEWIDTH>>1;
+ if(((drawx + spritewidth) < 0) || (drawx > al_get_bitmap_width(al_get_target_bitmap())) || ((drawy + spriteheight) < 0) || (drawy > al_get_bitmap_height(al_get_target_bitmap())))
+ return;
+
int sheetx, sheety;
if(tilelayout == BLOCKTILE)
{
@@ -677,7 +679,7 @@ void c_sprite::draw_world_offset(int x, int y, int z, Block * b, int tileoffset, sheety = ((sheetindex+tileoffset+randoffset) / SHEET_OBJECTSWIDE) * spriteheight;
}
ALLEGRO_COLOR shade_color = get_color(b);
- if(!b->designation.bits.pile && config.fog_of_war && (contentLoader.gameMode.control_mode == 1))
+ if(!b->designation.bits.pile && config.fog_of_war && (contentLoader->gameMode.g_mode == GAMEMODE_ADVENTURE))
{
shade_color.r *= 0.25f;
shade_color.g *= 0.25f;
@@ -687,22 +689,21 @@ void c_sprite::draw_world_offset(int x, int y, int z, Block * b, int tileoffset, {
if(fileindex < 0)
{
-#ifdef _DEBUG
- config.drawcount ++;
-#endif
+ if(config.block_count)
+ config.drawcount ++;
al_draw_tinted_bitmap_region(defaultsheet, premultiply(shade_color), sheetx, sheety+WALL_CUTOFF_HEIGHT, spritewidth, spriteheight-WALL_CUTOFF_HEIGHT, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT, 0);
}
else
{
-#ifdef _DEBUG
- config.drawcount ++;
-#endif
+ if(config.block_count)
+ config.drawcount ++;
+
al_draw_tinted_bitmap_region(getImgFile(fileindex), premultiply(shade_color), sheetx, (sheety)+WALL_CUTOFF_HEIGHT, spritewidth, spriteheight-WALL_CUTOFF_HEIGHT, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT, 0);
}
//draw cut-off floor thing
-#ifdef _DEBUG
- config.drawcount ++;
-#endif
+ if(config.block_count)
+ config.drawcount ++;
+
al_draw_bitmap_region(IMGObjectSheet,
TILEWIDTH * SPRITEFLOOR_CUTOFF, 0,
SPRITEWIDTH, SPRITEWIDTH,
@@ -714,16 +715,16 @@ void c_sprite::draw_world_offset(int x, int y, int z, Block * b, int tileoffset, {
if(fileindex < 0)
{
-#ifdef _DEBUG
- config.drawcount ++;
-#endif
+ if(config.block_count)
+ config.drawcount ++;
+
al_draw_tinted_bitmap_region(defaultsheet, premultiply(shade_color), sheetx, sheety, spritewidth, spriteheight, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT), 0);
}
else
{
-#ifdef _DEBUG
- config.drawcount ++;
-#endif
+ if(config.block_count)
+ config.drawcount ++;
+
al_draw_tinted_bitmap_region(getImgFile(fileindex), premultiply(shade_color), sheetx, sheety, spritewidth, spriteheight, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT), 0);
}
}
@@ -830,32 +831,35 @@ ALLEGRO_COLOR c_sprite::get_color(void* block) dayofLife = b->creature->birth_year*12*28 + b->creature->birth_time/1200;
if((!config.skipCreatureTypes) && (!config.skipCreatureTypesEx) && (!config.skipDescriptorColors))
{
+ t_creaturecaste & caste = contentLoader->Mats->raceEx[b->creature->race].castes[b->creature->caste];
+ std::vector<t_colormodifier> & colormods =caste.ColorModifier;
for(unsigned int j = 0; j<b->creature->nbcolors ; j++)
{
- if(strcmp(contentLoader.Mats->raceEx[b->creature->race].castes[b->creature->caste].ColorModifier[j].part, bodypart) == 0)
+ t_colormodifier & colormod = colormods[j];
+ if(colormods[j].part == bodypart)
{
- if(contentLoader.Mats->raceEx.at(b->creature->race).castes.at(b->creature->caste).ColorModifier.at(j).colorlist.size() > b->creature->color[j])
+ if(colormods[j].colorlist.size() > b->creature->color[j])
{
- uint32_t cr_color = contentLoader.Mats->raceEx.at(b->creature->race).castes.at(b->creature->caste).ColorModifier.at(j).colorlist.at(b->creature->color[j]);
- if(cr_color < contentLoader.Mats->color.size())
+ uint32_t cr_color = colormod.colorlist.at(b->creature->color[j]);
+ if(cr_color < contentLoader->Mats->color.size())
{
- if(contentLoader.Mats->raceEx[b->creature->race].castes[b->creature->caste].ColorModifier[j].startdate > 0)
+ if(colormod.startdate > 0)
{
- if((contentLoader.Mats->raceEx[b->creature->race].castes[b->creature->caste].ColorModifier[j].startdate <= dayofLife) &&
- (contentLoader.Mats->raceEx[b->creature->race].castes[b->creature->caste].ColorModifier[j].enddate > dayofLife))
+ if((colormod.startdate <= dayofLife) &&
+ (colormod.enddate > dayofLife))
{
return al_map_rgb_f(
- contentLoader.Mats->color[cr_color].red,
- contentLoader.Mats->color[cr_color].green,
- contentLoader.Mats->color[cr_color].blue);;
+ contentLoader->Mats->color[cr_color].red,
+ contentLoader->Mats->color[cr_color].green,
+ contentLoader->Mats->color[cr_color].blue);;
}
}
else
return al_map_rgb_f(
- contentLoader.Mats->color[cr_color].red,
- contentLoader.Mats->color[cr_color].green,
- contentLoader.Mats->color[cr_color].blue);
+ contentLoader->Mats->color[cr_color].red,
+ contentLoader->Mats->color[cr_color].green,
+ contentLoader->Mats->color[cr_color].blue);
}
}
}
|
