1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00
* CDefEssential is now useful
* initGameState shouldn't overwrite starting armies
* loading more graphics (small creature icons, large hero portraits)
* functions for getting current valueof morale/luck (unfinished)
* added in CLodHandler function that returns CDefEssential with images from desired .def
* copySurface works correctly (I hope)
This commit is contained in:
Michał W. Urbańczyk 2007-10-16 22:39:11 +00:00
parent 355e21b56a
commit 4cca2da9c0
15 changed files with 103 additions and 27 deletions

View File

@ -189,6 +189,8 @@ void CHeroList::select(int which)
LOCPLINT->adventureInt->terrain.currentPath = items[which].second;
draw();
LOCPLINT->adventureInt->townList.draw();
LOCPLINT->adventureInt->infoBar.draw(NULL);
}
void CHeroList::clickLeft(tribool down)
{
@ -1057,7 +1059,7 @@ void CResDataBar::draw()
}
CInfoBar::CInfoBar()
{
pos.x=604;
pos.x=605;
pos.y=389;
pos.w=194;
pos.h=186;

View File

@ -184,6 +184,7 @@ public:
class CInfoBar
:public virtual CIntObject
{
public:
CInfoBar();
void draw(void * specific=NULL); // if specific==0 function draws info about selected hero/town
};
@ -230,7 +231,7 @@ public:
CHeroList heroList;
CTownList townList;
CInfoBar infoBar;
struct CurrentSelection
{

View File

@ -10,7 +10,7 @@
#include "CPathfinder.h"
#include "mapHandler.h"
#include <sstream>
#include "SDL_Extensions.h"
int internalFunc(void * callback)
{
CCallback * cb = (CCallback*)callback;
@ -56,6 +56,12 @@ int internalFunc(void * callback)
readed>>src;
CGI->mh->getObjDescriptions(src);
break;
case 'I':
{
SDL_Surface * temp = LOCPLINT->infoWin(NULL);
blitAtWR(temp,605,389);
break;
}
case 'T': //test rect
readed>>src;
for(int g=0; g<8; ++g)

View File

@ -118,6 +118,24 @@ CPlayerInterface::CPlayerInterface(int Player, int serial)
CGI->localPlayer = playerID;
human=true;
hInfo = CGI->bitmaph->loadBitmap("HEROQVBK.bmp");
SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255));
slotsPos.push_back(std::pair<int,int>(44,82));
slotsPos.push_back(std::pair<int,int>(80,82));
slotsPos.push_back(std::pair<int,int>(116,82));
slotsPos.push_back(std::pair<int,int>(26,131));
slotsPos.push_back(std::pair<int,int>(62,131));
slotsPos.push_back(std::pair<int,int>(98,131));
slotsPos.push_back(std::pair<int,int>(134,131));
luck22 = CGI->spriteh->giveDefEss("ILCK22.DEF");
luck30 = CGI->spriteh->giveDefEss("ILCK30.DEF");
luck42 = CGI->spriteh->giveDefEss("ILCK42.DEF");
luck82 = CGI->spriteh->giveDefEss("ILCK82.DEF");
morale22 = CGI->spriteh->giveDefEss("IMRL22.DEF");
morale30 = CGI->spriteh->giveDefEss("IMRL30.DEF");
morale42 = CGI->spriteh->giveDefEss("IMRL42.DEF");
morale82 = CGI->spriteh->giveDefEss("IMRL82.DEF");
}
void CPlayerInterface::init(CCallback * CB)
{
@ -788,17 +806,27 @@ SDL_Surface * CPlayerInterface::infoWin(void * specific) //specific=0 => draws i
char * buf = new char[10];
SDL_Surface * ret = copySurface(hInfo);
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
blueToPlayersAdv(ret,playerID);
//blueToPlayersAdv(ret,playerID); // zygzyg - nie koloruje, tylko odrobine smieci
const CHeroInstance * curh = (const CHeroInstance *)adventureInt->selection.selected;
printAt(curh->name,15,75,GEOR13,zwykly,ret);
printAt(curh->name,75,15,GEOR13,zwykly,ret);
for (int i=0;i<PRIMARY_SKILLS;i++)
{
itoa(curh->primSkills[i],buf,10);
printAtMiddle(buf,87+27*i,69,GEOR13,zwykly,ret);
printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
}
for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
{
blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
itoa((*i).second.second,buf,10);
printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
}
blitAt(curh->type->portraitLarge,11,12,ret);
itoa(curh->mana,buf,10);
printAtMiddle(buf,169,109,GEORM,zwykly,ret);
printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
delete buf;
blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
//SDL_SaveBMP(ret,"inf1.bmp");
return ret;
}
else if (adventureInt->selection.type == TOWNI_TYPE)

View File

@ -14,7 +14,7 @@ class CCallback;
class CHeroInstance;
class CDefHandler;
struct HeroMoveDetails;
class CDefEssential;
class CIntObject //interface object
{
public:
@ -122,6 +122,9 @@ public:
std::vector<CSimpleWindow*> objsToBlit;
SDL_Surface * hInfo;
std::vector<std::pair<int, int> > slotsPos;
CDefEssential *luck22, *luck30, *luck42, *luck82,
*morale22, *morale30, *morale42, *morale82;
//overloaded funcs from Interface
void yourTurn();

22
CMT.cpp
View File

@ -127,18 +127,16 @@ void initGameState(CGameInfo * cgi)
if (vhi->portrait < 0)
vhi->portrait = vhi->type->ID;
CCreature * ct1 = &(cgi->creh->creatures[(cgi->creh->nameToID[vhi->type->refType2stack])]);
int cid1 = (cgi->creh->nameToID[vhi->type->refType2stack]);
int cid2 = (cgi->creh->nameToID[vhi->type->refType3stack]);
vhi->army.slots[0].first = &(cgi->creh->creatures[(cgi->creh->nameToID[vhi->type->refType1stack])]);
vhi->army.slots[0].second = (rand()%(vhi->type->high1stack-vhi->type->low1stack))+vhi->type->low1stack;
vhi->army.slots[1].first = &(cgi->creh->creatures[(cgi->creh->nameToID[vhi->type->refType2stack])]);
vhi->army.slots[1].second = (rand()%(vhi->type->high2stack-vhi->type->low2stack))+vhi->type->low2stack;
vhi->army.slots[2].first = &(cgi->creh->creatures[(cgi->creh->nameToID[vhi->type->refType3stack])]);
vhi->army.slots[2].second = (rand()%(vhi->type->high3stack-vhi->type->low3stack))+vhi->type->low3stack;
//initial army
if (!vhi->army.slots.size())
{
vhi->army.slots[0].first = &(cgi->creh->creatures[(cgi->creh->nameToID[vhi->type->refType1stack])]);
vhi->army.slots[0].second = (rand()%(vhi->type->high1stack-vhi->type->low1stack))+vhi->type->low1stack;
vhi->army.slots[1].first = &(cgi->creh->creatures[(cgi->creh->nameToID[vhi->type->refType2stack])]);
vhi->army.slots[1].second = (rand()%(vhi->type->high2stack-vhi->type->low2stack))+vhi->type->low2stack;
vhi->army.slots[2].first = &(cgi->creh->creatures[(cgi->creh->nameToID[vhi->type->refType3stack])]);
vhi->army.slots[2].second = (rand()%(vhi->type->high3stack-vhi->type->low3stack))+vhi->type->low3stack;
}
cgi->state->players[vhi->owner].heroes.push_back(vhi);

View File

@ -16,9 +16,7 @@ SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates ne
SDL_Surface * CSDL_Ext::copySurface(SDL_Surface * mod) //returns copy of given surface
{
SDL_Surface * ret = newSurface(mod->w,mod->h,mod);
SDL_BlitSurface(mod,NULL,ret,NULL);
return ret;
return SDL_DisplayFormat(mod);
}
bool isItIn(const SDL_Rect * rect, int x, int y)
{

View File

@ -274,7 +274,8 @@ void CCreatureHandler::loadCreatures()
creatures.push_back(ncre);
}
std::ifstream ifs("config/crerefnam.txt");
//loading reference names
std::ifstream ifs("config/crerefnam.txt");
int tempi;
std::string temps;
for (;;)
@ -286,6 +287,16 @@ void CCreatureHandler::loadCreatures()
creatures[tempi].nameRef=temps;
}
ifs.close();
//loading 32x32px imgs
CDefHandler *smi = CGI->spriteh->giveDef("CPRSMALL.DEF");
smi->notFreeImgs = true;
for (int i=0; i<smi->ourImages.size(); i++)
{
boost::assign::insert(smallImgs)(i-2,smi->ourImages[i].bitmap);
}
delete smi;
}
void CCreatureHandler::loadAnimationInfo()

View File

@ -44,6 +44,7 @@ public:
class CCreatureHandler
{
public:
std::map<int,SDL_Surface*> smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border
std::vector<CCreature> creatures;
std::map<std::string,int> nameToID;
void loadCreatures();

Binary file not shown.

Binary file not shown.

View File

@ -30,7 +30,13 @@ void CHeroHandler::loadPortraits()
of>>path;
heroes[ID]->portraitSmall=CGI->bitmaph->loadBitmap(path);
if (!heroes[ID]->portraitSmall)
std::cout<<"Can't read portrait for "<<ID<<" ("<<path<<")\n";
std::cout<<"Can't read small portrait for "<<ID<<" ("<<path<<")\n";
path.replace(2,1,"L");
heroes[ID]->portraitLarge=CGI->bitmaph->loadBitmap(path);
if (!heroes[ID]->portraitLarge)
std::cout<<"Can't read large portrait for "<<ID<<" ("<<path<<")\n";
SDL_SetColorKey(heroes[ID]->portraitLarge,SDL_SRCCOLORKEY,SDL_MapRGB(heroes[ID]->portraitLarge->format,0,255,255));
}
of.close();
}
@ -500,6 +506,16 @@ bool CHeroInstance::canWalkOnSea() const
//TODO: write it - it should check if hero is flying, or something similiar
return false;
}
int CHeroInstance::getCurrentLuck() const
{
//TODO: write it
return 0;
}
int CHeroInstance::getCurrentMorale() const
{
//TODO: write it
return 0;
}
void CHeroHandler::initTerrainCosts()
{
std::ifstream inp;

View File

@ -27,7 +27,8 @@ public:
CHeroClass * heroClass;
EHeroClasses heroType; //hero class
//bool operator<(CHero& drugi){if (ID < drugi.ID) return true; else return false;}
SDL_Surface * portraitSmall; //48x32 p
SDL_Surface * portraitSmall; //48x32 px
SDL_Surface * portraitLarge; //58x64 px
};
class CHeroClass
@ -74,6 +75,8 @@ public:
void setPosition(int3 Pos, bool h3m); //as above, but sets position
bool canWalkOnSea() const;
int getCurrentLuck() const;
int getCurrentMorale() const;
//TODO: artifacts, known spells, commander, blessings, curses, morale/luck special modifiers
};

View File

@ -400,7 +400,7 @@ CDefHandler * CLodHandler::giveDef(std::string defName)
nh->alphaTransformed = false;
ret = nh;
}
else //we will decompressing file
else //we will decompress file
{
outp = new unsigned char[ourEntry->size];
FLOD.read((char*)outp, ourEntry->size);
@ -415,6 +415,14 @@ CDefHandler * CLodHandler::giveDef(std::string defName)
delete outp;
return ret;
}
CDefEssential * CLodHandler::giveDefEss(std::string defName)
{
CDefEssential * ret;
CDefHandler * temp = giveDef(defName);
ret = temp->essentialize();
delete temp;
return ret;
}
std::vector<CDefHandler *> CLodHandler::extractManyFiles(std::vector<std::string> defNamesIn)
{
std::vector<CDefHandler *> ret(defNamesIn.size());

View File

@ -65,6 +65,7 @@ public:
int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
std::vector<CDefHandler *> extractManyFiles(std::vector<std::string> defNamesIn); //extrats given files (defs only)
CDefHandler * giveDef(std::string defName);
CDefEssential * giveDefEss(std::string defName);
std::string getTextFile(std::string name); //extracts one file
void extract(std::string FName);
void extractFile(std::string FName, std::string name); //extracts a specific file