1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

* probably fixed #8 from 0.7b forum

* fixed blockmap for obstacle 10
* better handling of creature animation framesInGroup
* vcmiistari no longer gives creature spell-like abilities
* probably correct calculation of occupiable hexes on battlefield
This commit is contained in:
mateuszb 2009-02-20 13:06:20 +00:00
parent fd66234a39
commit 2e47b5ce10
9 changed files with 855 additions and 877 deletions

View File

@ -866,6 +866,18 @@ bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
return true; return true;
} }
void CBattleInterface::handleStartMoving(int number)
{
for(int i=0; i<creAnims[number]->framesInGroup(20)*getAnimSpeedMultiplier()-1; ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
if((animCount+1)%(4/animSpeed)==0)
creAnims[number]->incrementFrame();
}
}
void CBattleInterface::bOptionsf() void CBattleInterface::bOptionsf()
{ {
CGI->curh->changeGraphic(0,0); CGI->curh->changeGraphic(0,0);
@ -967,7 +979,7 @@ void CBattleInterface::stackActivated(int number)
void CBattleInterface::stackMoved(int number, int destHex, bool endMoving) void CBattleInterface::stackMoved(int number, int destHex, bool endMoving)
{ {
bool startMoving = creAnims[number]->type==20; bool startMoving = creAnims[number]->getType()==20;
//a few useful variables //a few useful variables
int curStackPos = LOCPLINT->cb->battleGetPos(number); int curStackPos = LOCPLINT->cb->battleGetPos(number);
int steps = creAnims[number]->framesInGroup(0)*getAnimSpeedMultiplier()-1; int steps = creAnims[number]->framesInGroup(0)*getAnimSpeedMultiplier()-1;
@ -977,14 +989,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool endMoving)
if(startMoving) //animation of starting move; some units don't have this animation (ie. halberdier) if(startMoving) //animation of starting move; some units don't have this animation (ie. halberdier)
{ {
CGI->curh->hide(); CGI->curh->hide();
for(int i=0; i<creAnims[number]->framesInGroup(20)*getAnimSpeedMultiplier()-1; ++i) handleStartMoving(number);
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
if((animCount+1)%(4/animSpeed)==0)
creAnims[number]->incrementFrame();
}
} }
int mutPos = BattleInfo::mutualPosition(curStackPos, destHex); int mutPos = BattleInfo::mutualPosition(curStackPos, destHex);
@ -1200,6 +1205,11 @@ void CBattleInterface::stacksAreAttacked(std::vector<CBattleInterface::SStackAtt
void CBattleInterface::stackAttacking(int ID, int dest) void CBattleInterface::stackAttacking(int ID, int dest)
{ {
if(attackingInfo == NULL && creAnims[ID]->getType() == 20)
{
handleStartMoving(ID);
creAnims[ID]->setType(2);
}
while(attackingInfo != NULL || creAnims[ID]->getType()!=2) while(attackingInfo != NULL || creAnims[ID]->getType()!=2)
{ {
show(); show();

View File

@ -228,6 +228,7 @@ public:
void keyPressed(const SDL_KeyboardEvent & key); void keyPressed(const SDL_KeyboardEvent & key);
void mouseMoved(const SDL_MouseMotionEvent &sEvent); void mouseMoved(const SDL_MouseMotionEvent &sEvent);
bool reverseCreature(int number, int hex, bool wideTrick = false); //reverses animation of given creature playing animation of reversing bool reverseCreature(int number, int hex, bool wideTrick = false); //reverses animation of given creature playing animation of reversing
void handleStartMoving(int number); //animation of starting move; some units don't have this animation (ie. halberdier)
struct SStackAttackedInfo struct SStackAttackedInfo
{ {

View File

@ -271,7 +271,7 @@ std::vector<int> BattleInfo::getAccessibility(int stackID, bool addOccupiable)
std::vector<int> rem; std::vector<int> rem;
for(int b=0; b<BFIELD_SIZE; ++b) for(int b=0; b<BFIELD_SIZE; ++b)
{ {
if( ac[b] && !ac[b-1] && !ac[b+1] && b%BFIELD_WIDTH != 0 && b%BFIELD_WIDTH != (BFIELD_WIDTH-1)) if( ac[b] && (!ac[b-1] || dist[b-1] > s->speed() ) && ( !ac[b+1] || dist[b+1] > s->speed() ) && b%BFIELD_WIDTH != 0 && b%BFIELD_WIDTH != (BFIELD_WIDTH-1))
{ {
rem.push_back(b); rem.push_back(b);
} }

View File

@ -2104,7 +2104,7 @@ void CPlayerInterface::actionStarted(const BattleAction* action)
} }
if(!stack) if(!stack)
{ {
tlog1<<"Something wrong with stackNumber in actionStarted"<<std::endl; tlog1<<"Something wrong with stackNumber in actionStarted. Stack number: "<<action->stackNumber<<std::endl;
return; return;
} }

File diff suppressed because it is too large Load Diff

View File

@ -8,25 +8,10 @@ int CCreatureAnimation::getType() const
void CCreatureAnimation::setType(int type) void CCreatureAnimation::setType(int type)
{ {
this->type = type; this->type = type;
curFrame = 0; internalFrame = 0;
if(type!=-1) if(type!=-1)
{ {
if(SEntries[curFrame].group!=type) //rewind curFrame = frameGroups[type][0];
{
int j=-1; //first frame in displayed group
for(size_t g=0; g<SEntries.size(); ++g)
{
if(SEntries[g].group==type && j==-1)
{
j = g;
break;
}
}
if(curFrame != -1)
{
curFrame = j;
}
}
} }
else else
{ {
@ -37,7 +22,7 @@ void CCreatureAnimation::setType(int type)
} }
} }
CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL) CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), internalFrame(0)
{ {
FDef = CDefHandler::Spriteh->giveFile(name); //load main file FDef = CDefHandler::Spriteh->giveFile(name); //load main file
@ -64,35 +49,28 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL)
totalEntries=0; totalEntries=0;
for (int z=0; z<totalBlocks; z++) for (int z=0; z<totalBlocks; z++)
{ {
std::vector<int> frameIDs;
int group = readNormalNr(i,4); i+=4; //block ID int group = readNormalNr(i,4); i+=4; //block ID
totalInBlock = readNormalNr(i,4); i+=4; totalInBlock = readNormalNr(i,4); i+=4;
for (j=SEntries.size(); j<totalEntries+totalInBlock; j++) for (j=SEntries.size(); j<totalEntries+totalInBlock; j++)
{ {
SEntries.push_back(SEntry()); SEntries.push_back(SEntry());
SEntries[j].group = group; SEntries[j].group = group;
frameIDs.push_back(j);
} }
int unknown2 = readNormalNr(i,4); i+=4; //TODO use me int unknown2 = readNormalNr(i,4); i+=4; //TODO use me
int unknown3 = readNormalNr(i,4); i+=4; //TODO use me int unknown3 = readNormalNr(i,4); i+=4; //TODO use me
for (j=0; j<totalInBlock; j++) i+=13*totalInBlock; //ommiting names
{
for (int k=0;k<13;k++) Buffer[k]=FDef[i+k];
i+=13;
SEntries[totalEntries+j].name=Buffer;
}
for (j=0; j<totalInBlock; j++) for (j=0; j<totalInBlock; j++)
{ {
SEntries[totalEntries+j].offset = readNormalNr(i,4); SEntries[totalEntries+j].offset = readNormalNr(i,4); i+=4;
int unknown4 = readNormalNr(i,4); i+=4; //TODO use me
} }
//totalEntries+=totalInBlock; //totalEntries+=totalInBlock;
for(int hh=0; hh<totalInBlock; ++hh) for(int hh=0; hh<totalInBlock; ++hh)
{ {
++totalEntries; ++totalEntries;
} }
} frameGroups[group] = frameIDs;
for(j=0; j<SEntries.size(); ++j)
{
SEntries[j].name = SEntries[j].name.substr(0, SEntries[j].name.find('.')+4);
} }
//init vars //init vars
@ -130,22 +108,12 @@ int CCreatureAnimation::nextFrameMiddle(SDL_Surface *dest, int x, int y, bool at
} }
void CCreatureAnimation::incrementFrame() void CCreatureAnimation::incrementFrame()
{ {
curFrame++; curFrame = frameGroups[type][(internalFrame++)%frameGroups[type].size()];
if(type!=-1) if(type!=-1)
{ {
if(curFrame==SEntries.size() || SEntries[curFrame].group!=type) //rewind if(internalFrame == frameGroups[type].size()) //rewind
{ {
int j=-1; //first frame in displayed group curFrame = frameGroups[type][0];
for(size_t g=0; g<SEntries.size(); ++g)
{
if(SEntries[g].group==type)
{
j = g;
break;
}
}
if(curFrame!=-1)
curFrame = j;
} }
} }
else else
@ -264,13 +232,9 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
int CCreatureAnimation::framesInGroup(int group) const int CCreatureAnimation::framesInGroup(int group) const
{ {
int ret = 0; //number of frames in given group if(frameGroups.find(group) == frameGroups.end())
for(size_t g=0; g<SEntries.size(); ++g) return 0;
{ return frameGroups.find(group)->second.size();
if(SEntries[g].group == group)
++ret;
}
return ret;
} }
CCreatureAnimation::~CCreatureAnimation() CCreatureAnimation::~CCreatureAnimation()
@ -286,8 +250,8 @@ inline void CCreatureAnimation::putPixel(
const BMPPalette & color, const BMPPalette & color,
const unsigned char & palc, const unsigned char & palc,
const bool & yellowBorder const bool & yellowBorder
) const { ) const
{
if(palc!=0) if(palc!=0)
{ {
Uint8 * p = (Uint8*)dest->pixels + ftcp*3; Uint8 * p = (Uint8*)dest->pixels + ftcp*3;

View File

@ -15,7 +15,6 @@ private:
int * RLEntries; int * RLEntries;
struct SEntry struct SEntry
{ {
std::string name;
int offset; int offset;
int group; int group;
} ; } ;
@ -33,8 +32,9 @@ private:
//////////// ////////////
unsigned char * FDef; //animation raw data unsigned char * FDef; //animation raw data
int curFrame; //number of currently displayed frame int curFrame, internalFrame; //number of currently displayed frame
unsigned int frames; //number of frames unsigned int frames; //number of frames
std::map<int, std::vector<int> > frameGroups; //groups of frames; [groupID] -> vector of frame IDs in group
public: public:
int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1]) int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
int fullWidth, fullHeight; //read-only, please! int fullWidth, fullHeight; //read-only, please!

View File

@ -26,7 +26,7 @@ BATTLE OBSTACLES
7 OBDRK02.DEF LXX 1111110000000010000000100 7 OBDRK02.DEF LXX 1111110000000010000000100
8 OBDRK03.DEF X 1111110000000010000000100 8 OBDRK03.DEF X 1111110000000010000000100
9 OBDRK04.DEF LXX 1111110000000010000000100 9 OBDRK04.DEF LXX 1111110000000010000000100
10 OBDSH01.DEF XX 1111110000000010000000100 10 OBDSH01.DEF LXX 1111110000000010000000100
93 OBDSM01.DEF NXXLNXXLNNXX 1100000000000000000000000 93 OBDSM01.DEF NXXLNXXLNNXX 1100000000000000000000000
17 OBDSM02.DEF XXLNX 1111100000000010000000100 17 OBDSM02.DEF XXLNX 1111100000000010000000100
18 OBDSS17.DEF XXLNXXX 1111100000000010000000100 18 OBDSS17.DEF XXLNXXX 1111100000000010000000100

View File

@ -1005,7 +1005,10 @@ upgend:
ChangeSpells cs; ChangeSpells cs;
cs.learn = 1; cs.learn = 1;
for(int i=0;i<VLC->spellh->spells.size();i++) for(int i=0;i<VLC->spellh->spells.size();i++)
cs.spells.insert(i); {
if(!VLC->spellh->spells[i].creatureAbility)
cs.spells.insert(i);
}
sm.hid = cs.hid = gs->players[*players.begin()].currentSelection; sm.hid = cs.hid = gs->players[*players.begin()].currentSelection;
sm.val = 999; sm.val = 999;
if(gs->getHero(cs.hid)) if(gs->getHero(cs.hid))