1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +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 "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)
{
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()
{
bOptions->activate();
}
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
#include "global.h"
#include "CPlayerInterface.h"
class CCreatureSet;
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:
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
void activate();
void deactivate();
void show(SDL_Surface * to);
};

View File

@ -1,5 +1,6 @@
#include "CGameState.h"
#include "CGameInterface.h"
#include "CPlayerInterface.h"
#include <algorithm>
class CStack
{
@ -21,6 +22,7 @@ public:
}
} cmpst ;
void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2)
{
curB = new BattleInfo();
@ -53,27 +55,43 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
side = true;
else
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++;
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
}
curB->round++;
while(true) //do zwyciestwa jednej ze stron
{
for(int i=0;i<stacks.size();i++)
{
curB->activeStack = i;
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
}
}
//while(true) //do zwyciestwa jednej ze stron
//{
// for(int i=0;i<stacks.size();i++)
// {
// curB->activeStack = i;
// if(stacks[i]->alive) //niech interfejs ruszy oddzialem
// {
// 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++)
delete stacks[i];

View File

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

View File

@ -630,12 +630,19 @@ void CHeroScript::newObject(CGObjectInstance *os)
void CHeroScript::onHeroVisit(CGObjectInstance *os, int heroID)
{
//TODO: check for allies
cb->startBattle(
&(static_cast<CGHeroInstance*>(heroes[heroID]))->army,
&(static_cast<CGHeroInstance*>(os))->army,
os->pos,
static_cast<CGHeroInstance*>(heroes[heroID]),
static_cast<CGHeroInstance*>(os));
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*>(os))->army,
os->pos,
static_cast<CGHeroInstance*>(heroes[heroID]),
static_cast<CGHeroInstance*>(os));*/
}
}
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;
//TODO: zrobic secik w sposob wyrafinowany
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
{

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)
{
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;
}
@ -582,7 +584,9 @@ int _tmain(int argc, _TCHAR* argv[])
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;
}
@ -640,7 +644,9 @@ int _tmain(int argc, _TCHAR* argv[])
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;
}
@ -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("AF07.DEF")); //pink
for(int q=0; q<8; ++q)
{
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)
{
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;
}

View File

@ -1848,9 +1848,11 @@ void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
}
void CPlayerInterface::battleStart(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, tribool side) //called by engine when battle starts; side=0 - left, side=1 - right
{
{
curint->deactivate();
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

View File

@ -814,6 +814,20 @@ void CMapHandler::init()
std::cout<<"\tMaking object rects: "<<th.getDif()<<std::endl;
calculateBlockedPos();
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)
@ -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);
pp.y+=imgVal*2-32;
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)
{
@ -951,7 +965,10 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
SDL_Rect bufr = sr;
bufr.x-=2*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;
}
}

View File

@ -73,6 +73,7 @@ public:
std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
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