1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* partially done attacking in battles

* screen isn't now refreshed while blitting creature info window
* r-click creature info windows in battles
* a few minor things
This commit is contained in:
mateuszb 2008-05-27 13:16:35 +00:00
parent b00cc9c628
commit 1aa758a737
10 changed files with 273 additions and 59 deletions

View File

@ -266,8 +266,6 @@ void CBattleInterface::show(SDL_Surface * to)
}
}
//units shown
CSDL_Ext::update();
}
bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
@ -278,6 +276,7 @@ bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
for(int g=0; g<creAnims[number]->framesInGroup(8); ++g)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
creDir[number] = !creDir[number];
@ -296,6 +295,7 @@ bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
for(int g=0; g<creAnims[number]->framesInGroup(7); ++g)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
creAnims[number]->setType(2);
@ -379,6 +379,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo
for(int i=0; i<creAnims[number]->framesInGroup(20); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
}
@ -445,6 +446,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo
break;
}
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
if( (LOCPLINT->cb->battleGetStackByID(number).owner == attackingHeroInstance->tempOwner ) != creDir[number])
@ -512,6 +514,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo
break;
}
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
}
@ -521,6 +524,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo
for(int i=0; i<creAnims[number]->framesInGroup(21); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
}
@ -539,8 +543,147 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo
creAnims[number]->pos.y = coords.second;
}
void CBattleInterface::stackIsAttacked(int ID)
{
}
void CBattleInterface::stackAttacking(int ID, int dest)
{
CStack aStack = LOCPLINT->cb->battleGetStackByID(ID); //attacking stack
if(aStack.creature->isDoubleWide())
{
switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
{
case 0:
/*reverseCreature(ID, aStack.position, true);
creAnims[ID]->setType(10);
for(int i=0; i<creAnims[ID]->framesInGroup(10); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
reverseCreature(ID, aStack.position, true);*/
break;
case 1:
creAnims[ID]->setType(10);
for(int i=0; i<creAnims[ID]->framesInGroup(10); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
break;
case 2:
creAnims[ID]->setType(11);
for(int i=0; i<creAnims[ID]->framesInGroup(11); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
break;
case 3:
creAnims[ID]->setType(12);
for(int i=0; i<creAnims[ID]->framesInGroup(12); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
break;
case 4:
/*reverseCreature(ID, aStack.position, true);
creAnims[ID]->setType(12);
for(int i=0; i<creAnims[ID]->framesInGroup(12); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
reverseCreature(ID, aStack.position, true);*/
break;
case 5:
/*reverseCreature(ID, aStack.position, true);
creAnims[ID]->setType(11);
for(int i=0; i<creAnims[ID]->framesInGroup(11); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
reverseCreature(ID, aStack.position, true);*/
break;
}
creAnims[ID]->setType(2);
}
else //else for if(aStack.creature->isDoubleWide())
{
switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
{
case 0:
reverseCreature(ID, aStack.position, true);
creAnims[ID]->setType(10);
for(int i=0; i<creAnims[ID]->framesInGroup(10); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
reverseCreature(ID, aStack.position, true);
break;
case 1:
creAnims[ID]->setType(10);
for(int i=0; i<creAnims[ID]->framesInGroup(10); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
break;
case 2:
creAnims[ID]->setType(11);
for(int i=0; i<creAnims[ID]->framesInGroup(11); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
break;
case 3:
creAnims[ID]->setType(12);
for(int i=0; i<creAnims[ID]->framesInGroup(12); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
break;
case 4:
reverseCreature(ID, aStack.position, true);
creAnims[ID]->setType(12);
for(int i=0; i<creAnims[ID]->framesInGroup(12); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
reverseCreature(ID, aStack.position, true);
break;
case 5:
reverseCreature(ID, aStack.position, true);
creAnims[ID]->setType(11);
for(int i=0; i<creAnims[ID]->framesInGroup(11); ++i)
{
show();
CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
reverseCreature(ID, aStack.position, true);
break;
}
creAnims[ID]->setType(2);
}
}
void CBattleInterface::newRound(int number)
@ -551,6 +694,18 @@ void CBattleInterface::newRound(int number)
void CBattleInterface::hexLclicked(int whichOne)
{
if((whichOne%17)!=0 && (whichOne%17)!=16) //if player is trying to attack enemey unit or move creature stack
{
int atCre = LOCPLINT->cb->battleGetStack(whichOne); //creature at destination tile; -1 if there is no one
//LOCPLINT->cb->battleGetCreature();
if(atCre==-1) //normal move action
{
BattleAction * ba = new BattleAction(); //to be deleted by engine
ba->actionType = 2;
ba->destinationTile = whichOne;
ba->stackNumber = activeStack;
givenCommand = ba;
}
else if(LOCPLINT->cb->battleGetStackByID(atCre).owner != attackingHeroInstance->tempOwner) //attacking
{
BattleAction * ba = new BattleAction(); //to be deleted by engine
ba->actionType = 6;
@ -559,6 +714,7 @@ void CBattleInterface::hexLclicked(int whichOne)
givenCommand = ba;
}
}
}
void CBattleInterface::showRange(SDL_Surface * to, int ID)
{
@ -689,6 +845,7 @@ void CBattleHex::activate()
Hoverable::activate();
MotionInterested::activate();
ClickableL::activate();
ClickableR::activate();
}
void CBattleHex::deactivate()
@ -696,6 +853,7 @@ void CBattleHex::deactivate()
Hoverable::deactivate();
MotionInterested::deactivate();
ClickableL::deactivate();
ClickableR::deactivate();
}
void CBattleHex::hover(bool on)
@ -731,6 +889,29 @@ void CBattleHex::clickLeft(boost::logic::tribool down)
}
}
void CBattleHex::clickRight(boost::logic::tribool down)
{
int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile
if(hovered && strictHovered && stID!=-1)
{
CStack myst = LOCPLINT->cb->battleGetStackByID(stID); //stack info
StackState *pom = NULL;
if(down)
{
pom = new StackState();
const CGHeroInstance *h = myst.owner == myInterface->attackingHeroInstance->tempOwner ? myInterface->attackingHeroInstance : myInterface->defendingHeroInstance;
pom->attackBonus = h->primSkills[0];
pom->defenseBonus = h->primSkills[1];
pom->luck = h->getCurrentLuck();
pom->morale = h->getCurrentMorale();
(new CCreInfoWindow(myst.creature->idNumber,0,pom,boost::function<void()>(),boost::function<void()>()))
->activate();
}
delete pom;
}
}
CBattleConsole::CBattleConsole() : lastShown(-1)
{
}

View File

@ -24,7 +24,7 @@ public:
class CBattleInterface;
class CBattleHex : public Hoverable, public MotionInterested, public ClickableL
class CBattleHex : public Hoverable, public MotionInterested, public ClickableL, public ClickableR
{
public:
unsigned int myNumber;
@ -40,6 +40,7 @@ public:
void deactivate();
void mouseMoved (SDL_MouseMotionEvent & sEvent);
void clickLeft(boost::logic::tribool down);
void clickRight(boost::logic::tribool down);
CBattleHex();
};
@ -113,7 +114,10 @@ public:
void stackRemoved(CStack stack); //stack disappeared from batlefiled
void stackActivated(int number); //active stack has been changed
void stackMoved(int number, int destHex, bool startMoving, bool endMoving); //stack with id number moved to destHex
void stackIsAttacked(int ID); //called when stack id attacked
void stackAttacking(int ID, int dest); //called when stack with id ID is attacking something on hex dest
void newRound(int number); //caled when round is ended; number is the number of round
void hexLclicked(int whichOne); //hex only call-in
friend CBattleHex;
};

View File

@ -215,6 +215,10 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
BattleAction ba = ((CPlayerInterface*)CGI->playerint[serialOwner])->activeStack(stacks[i]->ID);
switch(ba.actionType)
{
case 2: //walk
{
battleMoveCreatureStack(ba.stackNumber, ba.destinationTile);
}
case 3: //defend
{
break;
@ -229,6 +233,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
case 6: //walk or attack
{
battleMoveCreatureStack(ba.stackNumber, ba.destinationTile);
battleAttackCreatureStack(ba.stackNumber, ba.destinationTile);
break;
}
}
@ -295,7 +300,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
accessibility[k] = true;
for(int g=0; g<curB->stacks.size(); ++g)
{
if(curB->stacks[g]->owner == owner && curB->stacks[g]->ID != ID) //we don't want to lock enemy's positions and this units' position
if(curB->stacks[g]->ID != ID) //we don't want to lock enemy's positions and this units' position
{
accessibility[curB->stacks[g]->position] = false;
if(curB->stacks[g]->creature->isDoubleWide()) //if it's a double hex creature
@ -307,6 +312,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
}
}
}
accessibility[dest] = true;
if(curStack->creature->isDoubleWide()) //locking positions unreachable by two-hex creatures
{
bool mac[187];
@ -415,6 +421,23 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
return true;
}
bool CGameState::battleAttackCreatureStack(int ID, int dest)
{
int attackedCreaure = -1; //-1 - there is no attacked creature
for(int b=0; b<curB->stacks.size(); ++b) //TODO: make upgrades for two-hex cres.
{
if(curB->stacks[b]->position == dest)
{
attackedCreaure = curB->stacks[b]->ID;
break;
}
}
if(attackedCreaure == -1)
return false;
//LOCPLINT->cb->
return true;
}
std::vector<int> CGameState::battleGetRange(int ID)
{
int initialPlace=-1; //position of unit

View File

@ -90,6 +90,7 @@ private:
}
void battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2);
bool battleMoveCreatureStack(int ID, int dest);
bool battleAttackCreatureStack(int ID, int dest);
std::vector<int> battleGetRange(int ID); //called by std::vector<int> CCallback::battleGetAvailableHexes(int ID);
public:
friend CCallback;

View File

@ -837,10 +837,10 @@ int _tmain(int argc, _TCHAR* argv[])
}
std::cout<<"Opening map file: "<<mapname<<"\t\t"<<std::flush;
gzFile map = gzopen(mapname.c_str(),"rb");
std::string mapstr;int pom;
std::vector<unsigned char> mapstr; int pom;
while((pom=gzgetc(map))>=0)
{
mapstr+=pom;
mapstr.push_back(pom);
}
gzclose(map);
unsigned char *initTable = new unsigned char[mapstr.size()];

View File

@ -2073,6 +2073,11 @@ void CPlayerInterface::battleStackAttacking(int ID, int dest)
dynamic_cast<CBattleInterface*>(curint)->stackAttacking(ID, dest);
}
void CPlayerInterface::battleStackIsAttacked(int ID)
{
dynamic_cast<CBattleInterface*>(curint)->stackIsAttacked(ID);
}
void CPlayerInterface::showComp(SComponent comp)
{
adventureInt->infoBar.showComp(&comp,4000);
@ -2933,22 +2938,23 @@ CCreInfoWindow::CCreInfoWindow(int Cid, int Type, StackState *State, boost::func
anim->setType(1);
char pom[25];int hlp=0;
printAtMiddle(c->namePl,149,30,GEOR13,zwykly,bitmap); //creature name
printAtMiddleWB(c->namePl,149,30,GEOR13,100,zwykly,bitmap); //creature name
//atttack
printAt(CGI->preth->zelp[435].first,155,48,GEOR13,zwykly,bitmap);
printAtWB(CGI->preth->zelp[435].first,155,48,GEOR13,100,zwykly,bitmap);
itoa(c->attack,pom,10);
if(State && State->attackBonus)
{
int hlp = log10f(c->attack)+2;
pom[hlp-1] = ' '; pom[hlp] = '(';
itoa(c->attack+State->attackBonus,pom+hlp+1,10);
pom[hlp+2+(int)log10f(State->attackBonus+c->attack)] = ')';
hlp += 2+(int)log10f(State->attackBonus+c->attack);
pom[hlp] = ')'; pom[hlp+1] = '\0';
}
printTo(pom,276,61,GEOR13,zwykly,bitmap);
printToWB(pom,276,61,GEOR13,zwykly,bitmap);
//defense
printAt(CGI->preth->zelp[436].first,155,67,GEOR13,zwykly,bitmap);
printAtWB(CGI->preth->zelp[436].first,155,67,GEOR13,100,zwykly,bitmap);
itoa(c->defence,pom,10);
if(State && State->defenseBonus)
{
@ -2957,36 +2963,36 @@ CCreInfoWindow::CCreInfoWindow(int Cid, int Type, StackState *State, boost::func
itoa(c->defence+State->defenseBonus,pom+hlp+1,10);
pom[hlp+2+(int)log10f(State->defenseBonus+c->defence)] = ')';
}
printTo(pom,276,80,GEOR13,zwykly,bitmap);
printToWB(pom,276,80,GEOR13,zwykly,bitmap);
//shots
if(c->shots)
{
printAt(CGI->generaltexth->allTexts[198],155,86,GEOR13,zwykly,bitmap);
printAtWB(CGI->generaltexth->allTexts[198],155,86,GEOR13,100,zwykly,bitmap);
itoa(c->shots,pom,10);
printTo(pom,276,99,GEOR13,zwykly,bitmap);
printToWB(pom,276,99,GEOR13,zwykly,bitmap);
}
//damage
printAt(CGI->generaltexth->allTexts[199],155,105,GEOR13,zwykly,bitmap);
printAtWB(CGI->generaltexth->allTexts[199],155,105,GEOR13,100,zwykly,bitmap);
itoa(c->damageMin,pom,10);
hlp=log10f(c->damageMin)+2;
pom[hlp-1]=' '; pom[hlp]='-'; pom[hlp+1]=' ';
itoa(c->damageMax,pom+hlp+2,10);
printTo(pom,276,118,GEOR13,zwykly,bitmap);
printToWB(pom,276,118,GEOR13,zwykly,bitmap);
//health
printAt(CGI->preth->zelp[439].first,155,124,GEOR13,zwykly,bitmap);
printAtWB(CGI->preth->zelp[439].first,155,124,GEOR13,100,zwykly,bitmap);
itoa(c->hitPoints,pom,10);
printTo(pom,276,137,GEOR13,zwykly,bitmap);
printToWB(pom,276,137,GEOR13,zwykly,bitmap);
//remaining health - TODO: show during the battles
//printAt(CGI->preth->zelp[440].first,155,143,GEOR13,zwykly,bitmap);
//speed
printAt(CGI->preth->zelp[441].first,155,162,GEOR13,zwykly,bitmap);
printAtWB(CGI->preth->zelp[441].first,155,162,GEOR13,100,zwykly,bitmap);
itoa(c->speed,pom,10);
printTo(pom,276,175,GEOR13,zwykly,bitmap);
printToWB(pom,276,175,GEOR13,zwykly,bitmap);
//luck and morale

View File

@ -341,6 +341,7 @@ public:
void battleEnd(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector<int> capturedArtifacts, int expForWinner, bool winner);
void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving);
void battleStackAttacking(int ID, int dest);
void battleStackIsAttacked(int ID);
//-------------//

View File

@ -202,6 +202,36 @@ void CSDL_Ext::printTo(std::string text, int x, int y, TTF_Font * font, SDL_Colo
SDL_UpdateRect(dst,x-temp->w,y-temp->h,temp->w,temp->h);
SDL_FreeSurface(temp);
}
void CSDL_Ext::printToWB(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality)
{
if (text.length()==0)
return;
SDL_Surface * temp;
switch (quality)
{
case 0:
temp = TTF_RenderText_Solid(font,text.c_str(),kolor);
break;
case 1:
SDL_Color tem;
tem.b = 0xff-kolor.b;
tem.g = 0xff-kolor.g;
tem.r = 0xff-kolor.r;
tem.unused = 0xff-kolor.unused;
temp = TTF_RenderText_Shaded(font,text.c_str(),kolor,tem);
break;
case 2:
temp = TTF_RenderText_Blended(font,text.c_str(),kolor);
break;
default:
temp = TTF_RenderText_Blended(font,text.c_str(),kolor);
break;
}
SDL_BlitSurface(temp,NULL,dst,&genRect(temp->h,temp->w,x-temp->w,y-temp->h));
SDL_FreeSurface(temp);
}
void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC, Uint8 A)
{
Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC;

View File

@ -39,6 +39,7 @@ namespace CSDL_Ext
//void fullAlphaTransform(SDL_Surface *& src); //performs first and second alpha transform
Uint32 colorToUint32(const SDL_Color * color); //little endian only
void printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)
void printToWB(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)
void printAtMiddle(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest
void printAtMiddleWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
void printAtWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);

View File

@ -937,39 +937,6 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
}
}
//for (int i=0; i<FullHeight; ++i)
//{
// for (int j=0;j<FullWidth+add;j++)
// {
// if( i+y<dest->h && j+x<dest->w && i+y>=0 && j+x>=0)
// {
// unsigned char coln = FTemp[i*(FullWidth+add)+j]; //number of color from palette
// if(coln==0)
// continue;
// unsigned char* ptr = ((unsigned char*)dest->pixels + dest->format->BytesPerPixel * ((i + y)*dest->w + j + x));
// if(coln>7 || coln == 5) //normal or yellow border
// {
// *ptr = palette[coln].B;
// *(ptr+1) = palette[coln].G;
// *(ptr+2) = palette[coln].R;
// }
// else if(coln<5) //shadow
// {
// *ptr = ((*ptr) * (palette[coln].G + 50)) /200;
// *(ptr+1) = ((*(ptr+1)) * (palette[coln].G + 50)) /200 ;
// *(ptr+2) = ((*(ptr+2)) * (palette[coln].G + 50)) /200 ;
// }
// else if(coln == 6) //yellow border shadowed
// {
// *ptr = ((*ptr) + palette[coln-1].B) / 2;
// *(ptr+1) = ((*(ptr+1)) + palette[coln-1].G) / 2;
// *(ptr+2) = ((*(ptr+2)) + palette[coln-1].R) / 2;
// }
// }
// }
//}
//SDL_UpdateRect(dest, x, y, FullWidth+add, FullHeight);
return 0;