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

* reported problems with hero flags resolved

* a bit of battle interface
* heroes with same owner cannot fight
This commit is contained in:
mateuszb 2008-02-26 18:01:26 +00:00
parent 1e7f8984e2
commit 1580c71c78
9 changed files with 174 additions and 28 deletions

View File

@ -1,11 +1,81 @@
#include "CBattleInterface.h" #include "CBattleInterface.h"
#include "CGameInfo.h"
#include "hch\CLodHandler.h"
#include "SDL_Extensions.h"
#include "CAdvmapInterface.h"
#include "AdventureMapButton.h"
CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2) CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2)
{ {
std::vector< std::string > & backref = CGI->mh->battleBacks[ CGI->mh->ttiles[tile.x][tile.y][tile.z].terType ];
background = CGI->bitmaph->loadBitmap(backref[ rand() % backref.size()] );
menu = CGI->bitmaph->loadBitmap("CBAR.BMP");
CSDL_Ext::blueToPlayersAdv(menu, hero1->tempOwner);
blitAt(background, 0, 0);
blitAt(menu, 0, 556);
CSDL_Ext::update();
bOptions = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bOptionsf, 3, 561, "icm003.def", this, false, NULL, false);
//bOptions->activate();
} }
CBattleInterface::~CBattleInterface()
{
SDL_FreeSurface(background);
SDL_FreeSurface(menu);
//delete
}
void CBattleInterface::activate() void CBattleInterface::activate()
{ {
bOptions->activate();
} }
void CBattleInterface::deactivate() void CBattleInterface::deactivate()
{
bOptions->deactivate();
}
void CBattleInterface::show(SDL_Surface * to)
{
blitAt(background, 0, 0, to);
blitAt(menu, 0, 556, to);
bOptions->show(to);
}
void CBattleInterface::bOptionsf()
{
}
void CBattleInterface::bSurrenderf()
{
}
void CBattleInterface::bFleef()
{
}
void CBattleInterface::bAutofightf()
{
}
void CBattleInterface::bSpellf()
{
}
void CBattleInterface::bWaitf()
{
}
void CBattleInterface::bDefencef()
{
}
void CBattleInterface::bConsoleUpf()
{
}
void CBattleInterface::bConsoleDownf()
{ {
} }

View File

@ -1,13 +1,34 @@
#pragma once #pragma once
#include "global.h" #include "global.h"
#include "CPlayerInterface.h" #include "CPlayerInterface.h"
class CCreatureSet; class CCreatureSet;
class CGHeroInstance; class CGHeroInstance;
class CBattleInterface : public IActivable template <typename T> class AdventureMapButton;
class CBattleInterface : public IActivable, public IShowable
{ {
private:
SDL_Surface * background, * menu;
AdventureMapButton<CBattleInterface> * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
* bWait, * bDefence, * bConsoleUp, * bConsoleDown;
public: public:
CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2); CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2);
~CBattleInterface();
//button handle funcs:
void bOptionsf();
void bSurrenderf();
void bFleef();
void bAutofightf();
void bSpellf();
void bWaitf();
void bDefencef();
void bConsoleUpf();
void bConsoleDownf();
//end of button handle funcs
//napisz tu klase odpowiadajaca za wyswietlanie bitwy i obsluge uzytkownika, polecenia ma przekazywac callbackiem //napisz tu klase odpowiadajaca za wyswietlanie bitwy i obsluge uzytkownika, polecenia ma przekazywac callbackiem
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to);
}; };

View File

@ -1,5 +1,6 @@
#include "CGameState.h" #include "CGameState.h"
#include "CGameInterface.h" #include "CGameInterface.h"
#include "CPlayerInterface.h"
#include <algorithm> #include <algorithm>
class CStack class CStack
{ {
@ -21,6 +22,7 @@ public:
} }
} cmpst ; } cmpst ;
void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2) void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2)
{ {
curB = new BattleInfo(); curB = new BattleInfo();
@ -53,27 +55,43 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
side = true; side = true;
else else
return; //no witnesses return; //no witnesses
CGI->playerint[j->second.serial]->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); if(CGI->playerint[j->second.serial]->human)
{
((CPlayerInterface*)( CGI->playerint[j->second.serial] ))->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side);
}
else
{
//CGI->playerint[j->second.serial]->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side);
}
} }
} }
curB->round++; curB->round++;
if(curB->hero1->getSecSkillLevel(19)>=0 || curB->hero2->getSecSkillLevel(19)>=0) //someone has tactics if( (curB->hero1 && curB->hero1->getSecSkillLevel(19)>=0) || ( curB->hero2 && curB->hero2->getSecSkillLevel(19)>=0) )//someone has tactics
{ {
//TODO: wywolania dla rundy -1, ograniczenie pola ruchu, etc //TODO: wywolania dla rundy -1, ograniczenie pola ruchu, etc
} }
curB->round++; curB->round++;
while(true) //do zwyciestwa jednej ze stron //while(true) //do zwyciestwa jednej ze stron
{ //{
for(int i=0;i<stacks.size();i++) // for(int i=0;i<stacks.size();i++)
{ // {
curB->activeStack = i; // curB->activeStack = i;
if(stacks[i]->alive) //niech interfejs ruszy oddzialem // if(stacks[i]->alive) //niech interfejs ruszy oddzialem
CGI->playerint[(stacks[i]->owner)?(hero2->tempOwner):(hero1->tempOwner)]->activeStack(stacks[i]->ID); // {
//sprawdzic czy po tej akcji ktoras strona nie wygrala bitwy // if(CGI->playerint[(stacks[i]->owner)?(hero2->tempOwner):(hero1->tempOwner)]->human)
} // {
} // ((CPlayerInterface*)CGI->playerint[(stacks[i]->owner)?(hero2->tempOwner):(hero1->tempOwner)])->activeStack(stacks[i]->ID);
// }
// else
// {
// //CGI->playerint[(stacks[i]->owner)?(hero2->tempOwner):(hero1->tempOwner)]->activeStack(stacks[i]->ID);
// }
// }
// //sprawdzic czy po tej akcji ktoras strona nie wygrala bitwy
// }
//}
for(int i=0;i<stacks.size();i++) for(int i=0;i<stacks.size();i++)
delete stacks[i]; delete stacks[i];

View File

@ -7,6 +7,7 @@
#include "SDL.h" #include "SDL.h"
#include "SDL_Extensions.h" #include "SDL_Extensions.h"
#include "CAdvmapInterface.h" #include "CAdvmapInterface.h"
#include "hch\CLodHandler.h"
#include "AdventureMapButton.h" #include "AdventureMapButton.h"
#include "CMessage.h" #include "CMessage.h"
#include <sstream> #include <sstream>

View File

@ -630,12 +630,19 @@ void CHeroScript::newObject(CGObjectInstance *os)
void CHeroScript::onHeroVisit(CGObjectInstance *os, int heroID) void CHeroScript::onHeroVisit(CGObjectInstance *os, int heroID)
{ {
//TODO: check for allies //TODO: check for allies
cb->startBattle( if(static_cast<CGHeroInstance*>(heroes[heroID])->tempOwner == static_cast<CGHeroInstance*>(os)->tempOwner) //one of allied cases
{
//exchange
}
else
{
/*cb->startBattle(
&(static_cast<CGHeroInstance*>(heroes[heroID]))->army, &(static_cast<CGHeroInstance*>(heroes[heroID]))->army,
&(static_cast<CGHeroInstance*>(os))->army, &(static_cast<CGHeroInstance*>(os))->army,
os->pos, os->pos,
static_cast<CGHeroInstance*>(heroes[heroID]), static_cast<CGHeroInstance*>(heroes[heroID]),
static_cast<CGHeroInstance*>(os)); static_cast<CGHeroInstance*>(os));*/
}
} }
std::vector<int> CHeroScript::yourObjects() //returns IDs of objects which are handled by script std::vector<int> CHeroScript::yourObjects() //returns IDs of objects which are handled by script
{ {
@ -694,7 +701,7 @@ void CMonsterS::onHeroVisit(CGObjectInstance *os, int heroID)
CCreatureSet set; CCreatureSet set;
//TODO: zrobic secik w sposob wyrafinowany //TODO: zrobic secik w sposob wyrafinowany
set.slots[0] = std::pair<CCreature*,int>(&CGI->creh->creatures[os->subID],((CCreatureObjInfo*)os->info)->number); set.slots[0] = std::pair<CCreature*,int>(&CGI->creh->creatures[os->subID],((CCreatureObjInfo*)os->info)->number);
cb->startBattle(heroID,&set,os->pos); //cb->startBattle(heroID,&set,os->pos);
} }
std::vector<int> CMonsterS::yourObjects() //returns IDs of objects which are handled by script std::vector<int> CMonsterS::yourObjects() //returns IDs of objects which are handled by script
{ {

17
CMT.cpp
View File

@ -524,7 +524,9 @@ int _tmain(int argc, _TCHAR* argv[])
for(int ff=0; ff<cgi->heroh->flags1[q]->ourImages.size(); ++ff) for(int ff=0; ff<cgi->heroh->flags1[q]->ourImages.size(); ++ff)
{ {
CSDL_Ext::alphaTransform(cgi->heroh->flags1[q]->ourImages[ff].bitmap); SDL_SetColorKey(cgi->heroh->flags1[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB(cgi->heroh->flags1[q]->ourImages[ff].bitmap->format, 0, 255, 255)
);
} }
cgi->heroh->flags1[q]->alphaTransformed = true; cgi->heroh->flags1[q]->alphaTransformed = true;
} }
@ -582,7 +584,9 @@ int _tmain(int argc, _TCHAR* argv[])
for(int ff=0; ff<cgi->heroh->flags2[q]->ourImages.size(); ++ff) for(int ff=0; ff<cgi->heroh->flags2[q]->ourImages.size(); ++ff)
{ {
CSDL_Ext::alphaTransform(cgi->heroh->flags2[q]->ourImages[ff].bitmap); SDL_SetColorKey(cgi->heroh->flags2[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB(cgi->heroh->flags2[q]->ourImages[ff].bitmap->format, 0, 255, 255)
);
} }
cgi->heroh->flags2[q]->alphaTransformed = true; cgi->heroh->flags2[q]->alphaTransformed = true;
} }
@ -640,7 +644,9 @@ int _tmain(int argc, _TCHAR* argv[])
for(int ff=0; ff<cgi->heroh->flags3[q]->ourImages.size(); ++ff) for(int ff=0; ff<cgi->heroh->flags3[q]->ourImages.size(); ++ff)
{ {
CSDL_Ext::alphaTransform(cgi->heroh->flags3[q]->ourImages[ff].bitmap); SDL_SetColorKey(cgi->heroh->flags3[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB(cgi->heroh->flags3[q]->ourImages[ff].bitmap->format, 0, 255, 255)
);
} }
cgi->heroh->flags3[q]->alphaTransformed = true; cgi->heroh->flags3[q]->alphaTransformed = true;
} }
@ -654,6 +660,7 @@ int _tmain(int argc, _TCHAR* argv[])
cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF06.DEF")); //teal cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF06.DEF")); //teal
cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF07.DEF")); //pink cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF07.DEF")); //pink
for(int q=0; q<8; ++q) for(int q=0; q<8; ++q)
{ {
for(int o=0; o<cgi->heroh->flags4[q]->ourImages.size(); ++o) for(int o=0; o<cgi->heroh->flags4[q]->ourImages.size(); ++o)
@ -743,7 +750,9 @@ int _tmain(int argc, _TCHAR* argv[])
for(int ff=0; ff<cgi->heroh->flags4[q]->ourImages.size(); ++ff) for(int ff=0; ff<cgi->heroh->flags4[q]->ourImages.size(); ++ff)
{ {
CSDL_Ext::alphaTransform(cgi->heroh->flags4[q]->ourImages[ff].bitmap); SDL_SetColorKey(cgi->heroh->flags4[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB(cgi->heroh->flags4[q]->ourImages[ff].bitmap->format, 0, 255, 255)
);
} }
cgi->heroh->flags4[q]->alphaTransformed = true; cgi->heroh->flags4[q]->alphaTransformed = true;
} }

View File

@ -1851,6 +1851,8 @@ void CPlayerInterface::battleStart(CCreatureSet * army1, CCreatureSet * army2, i
{ {
curint->deactivate(); curint->deactivate();
curint = new CBattleInterface(army1,army2,tile,hero1,hero2); curint = new CBattleInterface(army1,army2,tile,hero1,hero2);
curint->activate();
LOCPLINT->objsToBlit.push_back(dynamic_cast<IShowable*>(curint));
} }
void CPlayerInterface::battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles) //called when battlefield is prepared, prior the battle beginning void CPlayerInterface::battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles) //called when battlefield is prepared, prior the battle beginning

View File

@ -814,6 +814,20 @@ void CMapHandler::init()
std::cout<<"\tMaking object rects: "<<th.getDif()<<std::endl; std::cout<<"\tMaking object rects: "<<th.getDif()<<std::endl;
calculateBlockedPos(); calculateBlockedPos();
std::cout<<"\tCalculating blockmap: "<<th.getDif()<<std::endl; std::cout<<"\tCalculating blockmap: "<<th.getDif()<<std::endl;
//initailizing battle backgrounds
std::ifstream bback("config/battleBack.txt");
battleBacks.resize(9);
for(int i=0; i<9; ++i) //9 - number of terrains battle can be fought on
{
int am;
bback>>am;
battleBacks[i].resize(am);
for(int f=0; f<am; ++f)
{
bback>>battleBacks[i][f];
}
}
} }
SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect) SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect)
@ -925,7 +939,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
CSDL_Ext::blit8bppAlphaTo24bpp(tb,&pp,su,&sr); CSDL_Ext::blit8bppAlphaTo24bpp(tb,&pp,su,&sr);
pp.y+=imgVal*2-32; pp.y+=imgVal*2-32;
sr.y-=16; sr.y-=16;
CSDL_Ext::blit8bppAlphaTo24bpp(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr); SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr);
} }
else if(themp && themp->moveDir && themp->isStanding && themp->ID!=62) //last condition - this is not prison) else if(themp && themp->moveDir && themp->isStanding && themp->ID!=62) //last condition - this is not prison)
{ {
@ -951,7 +965,10 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
SDL_Rect bufr = sr; SDL_Rect bufr = sr;
bufr.x-=2*32; bufr.x-=2*32;
bufr.y-=1*32; bufr.y-=1*32;
CSDL_Ext::blit8bppAlphaTo24bpp(CGI->heroh->flags4[themp->getOwner()]->ourImages[ getHeroFrameNum(themp->moveDir, !themp->isStanding) *8+heroAnim%imgVal].bitmap, NULL, su, &bufr); bufr.h = 64;
bufr.w = 96;
if(bufr.x-extRect->x>-64)
SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[ getHeroFrameNum(themp->moveDir, !themp->isStanding) *8+(heroAnim/4)%imgVal].bitmap, NULL, su, &bufr);
themp->flagPrinted = true; themp->flagPrinted = true;
} }
} }

View File

@ -73,6 +73,7 @@ public:
std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase) std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
std::map<int, CGDefInfo*> villages, forts, capitols; std::map<int, CGDefInfo*> villages, forts, capitols;
std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type
PseudoV< PseudoV< PseudoV<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile PseudoV< PseudoV< PseudoV<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile