1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-11 11:31:52 +02:00
- fixed crash at campaigns loading
- minor fixes
This commit is contained in:
Ivan Savenko 2011-11-25 19:41:23 +00:00
parent a62634cf94
commit 29f42aa873
8 changed files with 38 additions and 43 deletions

View File

@ -1520,7 +1520,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
if(!isActive() || LOCPLINT->ctrlPressed())//ctrl makes arrow move screen, not hero
break;
k -= SDLK_KP_0 + 1;
k -= SDLK_KP0 + 1;
if(k < 0 || k > 8 || key.state != SDL_PRESSED)
return;

View File

@ -53,8 +53,7 @@ SDL_Surface * CPCXConv::getSurface() const
int width = -1, height = -1;
Epcxformat format;
int fSize,y;
unsigned char add;
int fSize;
int it=0;
fSize = read_le_u32(pcx + it); it+=4;
@ -68,13 +67,16 @@ SDL_Surface * CPCXConv::getSurface() const
else
return NULL;
add = 4 - width%4;
if (add==4)
add=0;
if (format==PCX8B)
{
ret = SDL_CreateRGBSurface(SDL_SWSURFACE, width+add, height, 8, 0, 0, 0, 0);
ret = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8, 0, 0, 0, 0);
it = 0xC;
for (int i=0; i<height; i++)
{
memcpy((char*)ret->pixels + ret->pitch * i, pcx + it, width);
it+= width;
}
it = pcxs-256*3;
for (int i=0;i<256;i++)
@ -90,17 +92,7 @@ SDL_Surface * CPCXConv::getSurface() const
tp.b = pcx[it++];
#endif
tp.unused = 0;
*(ret->format->palette->colors+i) = tp;
}
for (y=height; y>0; --y)
{
it = 0xC + (y-1)*width;
memcpy((char*)ret->pixels + ret->pitch * (y-1), pcx + it, width);
if (add>0)
{
memset((char*)ret->pixels + ret->pitch * (y-1) + width, 0, add);
}
ret->format->palette->colors[i] = tp;
}
}
else
@ -114,19 +106,15 @@ SDL_Surface * CPCXConv::getSurface() const
int gmask = 0x00ff00;
int rmask = 0xff0000;
#endif
ret = SDL_CreateRGBSurface(SDL_SWSURFACE, width+add, height, 24, rmask, gmask, bmask, 0);
ret = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 24, rmask, gmask, bmask, 0);
for (y=height; y>0; y--)
it = 0xC;
for (int i=0; i<height; i++)
{
it = 0xC + (y-1)*width*3;
memcpy((char*)ret->pixels + ret->pitch * (y-1), pcx + it, width*3);
if (add>0)
{
memset((char*)ret->pixels + ret->pitch * (y-1) + width*3, 0, add*3);
}
memcpy((char*)ret->pixels + ret->pitch * i, pcx + it, width*3);
it+= width*3;
}
}
return ret;
}

View File

@ -270,12 +270,6 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details)
//TODO: smooth disappear / appear effect
}
if(details.start == details.end) //last step
{
eraseCurrentPathOf(ho);
return;
}
if (ho->pos != details.end //hero didn't change tile but visit succeeded
|| directlyAttackingCreature) // or creature was attacked from endangering tile.
{
@ -283,8 +277,8 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details)
}
else if(adventureInt->terrain.currentPath && ho->pos == details.end) //&& hero is moving
{
//remove one node from the path (the one we went)
removeLastNodeFromPath(ho);
if (adventureInt->terrain.currentPath->endPos() != details.end)
removeLastNodeFromPath(ho);
}
}

View File

@ -126,7 +126,9 @@ const char * CMediaHandler::extract (int index, int & size)
const char * CMediaHandler::extract (std::string srcName, int &size)
{
int index;
srcName.erase(srcName.find_last_of('.'));
size_t dotPos = srcName.find_last_of('.');
if (dotPos != std::string::npos)
srcName.erase(dotPos);
std::map<std::string, int>::iterator fit;
if ((fit = fimap.find(srcName)) != fimap.end())

View File

@ -2223,11 +2223,12 @@ std::vector<ui32> BattleInfo::calculateResistedStacks( const CSpell * sp, const
if(sp->positiveness >= 0 && (*it)->owner == casterSideOwner)
continue;
/*
const CGHeroInstance * bonusHero; //hero we should take bonuses from
if((*it)->owner == casterSideOwner)
bonusHero = caster;
else
bonusHero = hero2;
bonusHero = hero2;*/
int prob = (*it)->magicResistance(); //probability of resistance in %

View File

@ -61,6 +61,13 @@ std::vector<CCampaignHeader> CCampaignHandler::getCampaignHeaders(GetMode mode)
ret.push_back( getHeader(e.name, true) );
}
}
BOOST_FOREACH(Entry e, bitmaph_ab->entries)
{
if( e.type == FILE_CAMPAIGN && e.name != "TOSBLK1" )
{
ret.push_back( getHeader(e.name, true) );
}
}
}
@ -143,7 +150,7 @@ CCampaignHeader CCampaignHandler::readHeaderFromMemory( const unsigned char *buf
{
CCampaignHeader ret;
ret.version = read_le_u32(buffer + outIt); outIt+=4;
ret.mapVersion = read_le_u32(buffer + outIt);
ret.mapVersion = buffer[outIt++]; //1 byte only
ret.mapVersion -= 1; //change range of it from [1, 20] to [0, 19]
ret.name = readString(buffer, outIt);
ret.description = readString(buffer, outIt);

View File

@ -780,7 +780,7 @@ void CCreatureHandler::loadStackExp(Bonus & b, BonusList & bl, std::string & src
case 'U':
b.type = Bonus::UNDEAD; break;
default:
tlog3 << "Not parsed bonus " << buf << mod << "\n";
tlog5 << "Not parsed bonus " << buf << mod << "\n";
return;
break;
}
@ -879,7 +879,7 @@ void CCreatureHandler::loadStackExp(Bonus & b, BonusList & bl, std::string & src
b.type = Bonus::RECEPTIVE;
break;
default:
tlog3 << "Not parsed bonus " << buf << mod << "\n";
tlog5 << "Not parsed bonus " << buf << mod << "\n";
return;
}
break;
@ -908,7 +908,7 @@ void CCreatureHandler::loadStackExp(Bonus & b, BonusList & bl, std::string & src
b.additionalInfo = 3; //always expert?
break;
default:
tlog3 << "Not parsed bonus " << buf << mod << "\n";
tlog5 << "Not parsed bonus " << buf << mod << "\n";
return;
break;
}

View File

@ -28,6 +28,9 @@ JsonNode::JsonNode(std::string filename):
type(DATA_NULL)
{
FILE * file = fopen(filename.c_str(), "rb");
if (!file)
return;
fseek(file, 0, SEEK_END);
size_t datasize = ftell(file);
fseek(file, 0, SEEK_SET);