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

Continuation of splitting.

(don't try to compile this revision)
This commit is contained in:
Michał W. Urbańczyk 2008-06-13 08:16:51 +00:00
parent 7df624d919
commit 6ad729148e
21 changed files with 669 additions and 930 deletions

View File

@ -19,6 +19,7 @@
#include <sstream>
#include "AdventureMapButton.h"
#include "CHeroWindow.h"
#include "client/Graphics.h"
#pragma warning (disable : 4355)
extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
@ -679,14 +680,14 @@ void CInfoBar::draw(const CGObjectInstance * specific)
if(specific->ID == 34) //hero
{
if(LOCPLINT->graphics.heroWins.find(specific->subID)!=LOCPLINT->graphics.heroWins.end())
blitAt(LOCPLINT->graphics.heroWins[specific->subID],pos.x,pos.y);
if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end())
blitAt(graphics->heroWins[specific->subID],pos.x,pos.y);
}
else if (specific->ID == 98)
{
const CGTownInstance * t = static_cast<const CGTownInstance*>(specific);
if(LOCPLINT->graphics.townWins.find(t->identifier)!=LOCPLINT->graphics.townWins.end())
blitAt(LOCPLINT->graphics.townWins[t->identifier],pos.x,pos.y);
if(graphics->townWins.find(t->identifier)!=graphics->townWins.end())
blitAt(graphics->townWins[t->identifier],pos.x,pos.y);
}
//SDL_Surface * todr = LOCPLINT->infoWin(specific);

View File

@ -12,6 +12,7 @@
#include "CMessage.h"
#include "hch/CGeneralTextHandler.h"
#include "CCallback.h"
#include "client/Graphics.h"
extern TTF_Font * GEOR16;
CBuildingRect::CBuildingRect(Structure *Str)
:str(Str), moi(false), offset(0)
@ -414,7 +415,7 @@ void CCastleInterface::showAll(SDL_Surface * to)
int pomx, pomy;
pomx = 22 + (55*((i>3)?(i-4):i));
pomy = (i>3)?(507):(459);
blitAt(LOCPLINT->graphics.smallImgs[cid],pomx,pomy,to);
blitAt(graphics->smallImgs[cid],pomx,pomy,to);
std::ostringstream oss;
oss << '+' << town->creatureGrowth(i);
CSDL_Ext::printAtMiddle(oss.str(),pomx+16,pomy+37,GEOR13,zwykly,to);
@ -433,7 +434,7 @@ void CCastleInterface::showAll(SDL_Surface * to)
pom += F_NUMBER*2;
if(town->builded >= MAX_BUILDING_PER_TURN)
pom++;
blitAt(LOCPLINT->graphics.bigTownPic->ourImages[pom].bitmap,15,387,to);
blitAt(graphics->bigTownPic->ourImages[pom].bitmap,15,387,to);
//flag
if(town->getOwner()<PLAYER_LIMIT)
@ -1033,12 +1034,12 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod
if(it<4)
{
CSDL_Ext::printAtMiddle(buf,(bitmap->w/2-row1w/2)+77*it+16,ah+42,GEOR16,zwykly,bitmap);
blitAt(CGI->townh->resources->ourImages[cn].bitmap,(bitmap->w/2-row1w/2)+77*it++,ah,bitmap);
blitAt(graphics->resources32->ourImages[cn].bitmap,(bitmap->w/2-row1w/2)+77*it++,ah,bitmap);
}
else
{
CSDL_Ext::printAtMiddle(buf,(bitmap->w/2-row2w/2)+77*it+16-308,ah+42,GEOR16,zwykly,bitmap);
blitAt(CGI->townh->resources->ourImages[cn].bitmap,(bitmap->w/2-row2w/2)+77*it++ - 308,ah,bitmap);
blitAt(graphics->resources32->ourImages[cn].bitmap,(bitmap->w/2-row2w/2)+77*it++ - 308,ah,bitmap);
}
if(it==4)
ah+=75;

View File

@ -15,7 +15,7 @@
#include "hch/CArtHandler.h"
#include "hch\CAbilityHandler.h"
#include <sstream>
#include "client/Graphics.h"
extern SDL_Surface * screen;
extern TTF_Font * GEOR16;
@ -732,7 +732,7 @@ void CHeroWindow::redrawCurBack()
blitAt(skillpics->ourImages[4].bitmap, 20, 230, curBack);
blitAt(skillpics->ourImages[3].bitmap, 162, 230, curBack);
blitAt(curHero->type->portraitLarge, 19, 19, curBack);
blitAt(graphics->portraitLarge[curHero->subID], 19, 19, curBack);
CSDL_Ext::printAtMiddle(curHero->name, 190, 40, GEORXX, tytulowy, curBack);
@ -788,8 +788,8 @@ void CHeroWindow::redrawCurBack()
primarySkill4<<curHero->primSkills[3];
CSDL_Ext::printAtMiddle(primarySkill4.str(), 263, 165, TNRB16, zwykly, curBack);
blitAt(LOCPLINT->graphics.luck42->ourImages[curHero->getCurrentLuck()+3].bitmap, 239, 182, curBack);
blitAt(LOCPLINT->graphics.morale42->ourImages[curHero->getCurrentMorale()+3].bitmap, 181, 182, curBack);
blitAt(graphics->luck42->ourImages[curHero->getCurrentLuck()+3].bitmap, 239, 182, curBack);
blitAt(graphics->morale42->ourImages[curHero->getCurrentMorale()+3].bitmap, 181, 182, curBack);
blitAt(flags->ourImages[player].bitmap, 606, 8, curBack);
@ -797,14 +797,14 @@ void CHeroWindow::redrawCurBack()
for(int g=0; g<LOCPLINT->cb->howManyHeroes(); ++g)
{
const CGHeroInstance * cur = LOCPLINT->cb->getHeroInfo(player, g, false);
blitAt(cur->type->portraitSmall, 611, 87+g*54, curBack);
blitAt(graphics->portraitSmall[cur->subID], 611, 87+g*54, curBack);
//printing yellow border
if(cur->name == curHero->name)
{
for(int f=0; f<cur->type->portraitSmall->w; ++f)
for(int f=0; f<graphics->portraitSmall[cur->subID]->w; ++f)
{
for(int h=0; h<cur->type->portraitSmall->h; ++h)
if(f==0 || h==0 || f==cur->type->portraitSmall->w-1 || h==cur->type->portraitSmall->h-1)
for(int h=0; h<graphics->portraitSmall[cur->subID]->h; ++h)
if(f==0 || h==0 || f==graphics->portraitSmall[cur->subID]->w-1 || h==graphics->portraitSmall[cur->subID]->h-1)
{
CSDL_Ext::SDL_PutPixel(curBack, 611+f, 87+g*54+h, 240, 220, 120);
}
@ -863,7 +863,7 @@ void CHeroWindow::redrawCurBack()
}
//printing special ability
blitAt(CGI->heroh->un44->ourImages[curHero->subID].bitmap, 18, 180, curBack);
blitAt(graphics->un44->ourImages[curHero->subID].bitmap, 18, 180, curBack);
//printing necessery texts
CSDL_Ext::printAt(CGI->generaltexth->jktexts[6].substr(1, CGI->generaltexth->jktexts[6].size()-2), 69, 231, GEOR13, tytulowy, curBack);
@ -979,7 +979,7 @@ void CArtPlace::show(SDL_Surface *to)
{
if(ourArt)
{
blitAt(LOCPLINT->graphics.artDefs->ourImages[ourArt->id].bitmap, pos.x, pos.y, to);
blitAt(graphics->artDefs->ourImages[ourArt->id].bitmap, pos.x, pos.y, to);
}
if(clicked && active)
{

19
CMT.cpp
View File

@ -50,6 +50,7 @@
#include "boost/filesystem/operations.hpp"
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp>
#include "client\Graphics.h"
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
# include <io.h>
@ -370,11 +371,7 @@ int _tmain(int argc, _TCHAR* argv[])
CMusicHandler * mush = new CMusicHandler; //initializing audio
mush->initMusics();
//audio initialized
/*if(Mix_PlayMusic(mush->mainMenuWoG, -1)==-1) //uncomment this fragment to have music
{
printf("Mix_PlayMusic: %s\n", Mix_GetError());
// well, there's no music, but most games don't break without music...
}*/
//screen2 = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/);
//screen = SDL_ConvertSurface(screen2, screen2->format, SDL_SWSURFACE);
@ -390,8 +387,11 @@ int _tmain(int argc, _TCHAR* argv[])
cgi->spriteh->init(std::string("Data\\H3sprite.lod"));
BitmapHandler::bitmaph = cgi->bitmaph = new CLodHandler;
cgi->bitmaph->init(std::string("Data\\H3bitmap.lod"));
initDLL(cgi->bitmaph);
THC std::cout<<"Loading .lod files: "<<tmh.getDif()<<std::endl;
initDLL(cgi->bitmaph);
THC std::cout<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl;
graphics = new Graphics();
THC std::cout<<"Initializing game graphics: "<<tmh.getDif()<<std::endl;
boost::filesystem::directory_iterator enddir;
for (boost::filesystem::directory_iterator dir("Data");dir!=enddir;dir++)
@ -487,8 +487,6 @@ int _tmain(int argc, _TCHAR* argv[])
cgi->generaltexth = new CGeneralTextHandler;
cgi->generaltexth->load();
THC std::cout<<"Preparing more handlers: "<<tmh.getDif()<<std::endl;
cgi->heroh->loadHeroFlags();
THC std::cout<<"Initializing colours and flags: "<<tmh.getDif()<<std::endl;
CPreGame * cpg = new CPreGame(); //main menu and submenus
THC std::cout<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl;
cpg->mush = mush;
@ -566,11 +564,6 @@ int _tmain(int argc, _TCHAR* argv[])
initGameState(&ac->map,cgi);
THC std::cout<<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
/*for(int d=0; d<PLAYER_LIMIT; ++d)
{
cgi->playerint.push_back(NULL);
}*/
for (int i=0; i<cgi->scenarioOps.playerInfos.size();i++) //initializing interfaces
{

View File

@ -27,6 +27,7 @@
#include "CLua.h"
#include <cmath>
#include "client/CCreatureAnimation.h"
#include "client/Graphics.h"
using namespace CSDL_Ext;
extern TTF_Font * GEOR16;
@ -229,10 +230,10 @@ void CGarrisonSlot::show()
{
char* buf = new char[15];
itoa(count,buf,10);
blitAt(LOCPLINT->graphics.bigImgs[creature->idNumber],pos);
blitAt(graphics->bigImgs[creature->idNumber],pos);
printTo(buf,pos.x+56,pos.y+62,GEOR16,zwykly);
if(owner->highlighted==this)
blitAt(LOCPLINT->graphics.bigImgs[-1],pos);
blitAt(graphics->bigImgs[-1],pos);
if(owner->update)
updateRect(&pos,screen);
delete [] buf;
@ -242,7 +243,7 @@ void CGarrisonSlot::show()
SDL_Rect jakis1 = genRect(pos.h,pos.w,owner->offx+ID*(pos.w+owner->interx),owner->offy+upg*(pos.h+owner->intery)), jakis2 = pos;
SDL_BlitSurface(owner->sur,&jakis1,screen,&jakis2);
if(owner->splitting)
blitAt(LOCPLINT->graphics.bigImgs[-1],pos);
blitAt(graphics->bigImgs[-1],pos);
if(owner->update)
SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h);
}
@ -552,16 +553,16 @@ SDL_Surface * SComponent::getImg()
switch (type)
{
case primskill:
return CGI->heroh->pskillsb->ourImages[subtype].bitmap;
return graphics->pskillsb->ourImages[subtype].bitmap;
break;
case secskill:
return CGI->abilh->abils82->ourImages[subtype*3 + 3 + val].bitmap;
break;
case resource:
return CGI->heroh->resources->ourImages[subtype].bitmap;
return graphics->resources->ourImages[subtype].bitmap;
break;
case experience:
return CGI->heroh->pskillsb->ourImages[4].bitmap;
return graphics->pskillsb->ourImages[4].bitmap;
break;
}
return NULL;
@ -887,60 +888,6 @@ void TimeInterested::deactivate()
LOCPLINT->
timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),this));
}
CPlayerInterface::Graphics::Graphics()
{
artDefs = CDefHandler::giveDef("ARTIFACT.DEF");
hInfo = BitmapHandler::loadBitmap("HEROQVBK.bmp");
SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255));
tInfo = BitmapHandler::loadBitmap("TOWNQVBK.bmp");
SDL_SetColorKey(tInfo,SDL_SRCCOLORKEY,SDL_MapRGB(tInfo->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 = CDefHandler::giveDefEss("ILCK22.DEF");
luck30 = CDefHandler::giveDefEss("ILCK30.DEF");
luck42 = CDefHandler::giveDefEss("ILCK42.DEF");
luck82 = CDefHandler::giveDefEss("ILCK82.DEF");
morale22 = CDefHandler::giveDefEss("IMRL22.DEF");
morale30 = CDefHandler::giveDefEss("IMRL30.DEF");
morale42 = CDefHandler::giveDefEss("IMRL42.DEF");
morale82 = CDefHandler::giveDefEss("IMRL82.DEF");
halls = CDefHandler::giveDefEss("ITMTLS.DEF");
forts = CDefHandler::giveDefEss("ITMCLS.DEF");
bigTownPic = CDefHandler::giveDefEss("ITPT.DEF");
std::ifstream ifs;
ifs.open("config/cr_bgs.txt");
while(!ifs.eof())
{
int id;
std::string name;
ifs >> id >> name;
backgrounds[id]=BitmapHandler::loadBitmap(name);
}
ifs.close();
ifs.clear();
//loading 32x32px imgs
CDefHandler *smi = CDefHandler::giveDef("CPRSMALL.DEF");
smi->notFreeImgs = true;
for (int i=0; i<smi->ourImages.size(); i++)
{
smallImgs[i-2] = smi->ourImages[i].bitmap;
}
delete smi;
smi = CDefHandler::giveDef("TWCRPORT.DEF");
smi->notFreeImgs = true;
for (int i=0; i<smi->ourImages.size(); i++)
{
bigImgs[i-2] = smi->ourImages[i].bitmap;
}
delete smi;
}
CPlayerInterface::CPlayerInterface(int Player, int serial)
{
playerID=Player;
@ -958,13 +905,13 @@ void CPlayerInterface::init(ICallback * CB)
for(int i=0;i<hh.size();i++)
{
SDL_Surface * pom = infoWin(hh[i]);
graphics.heroWins.insert(std::pair<int,SDL_Surface*>(hh[i]->subID,pom));
graphics->heroWins.insert(std::pair<int,SDL_Surface*>(hh[i]->subID,pom));
}
std::vector<const CGTownInstance*> tt = cb->getTownsInfo(false);
for(int i=0;i<tt.size();i++)
{
SDL_Surface * pom = infoWin(tt[i]);
graphics.townWins.insert(std::pair<int,SDL_Surface*>(tt[i]->identifier,pom));
graphics->townWins.insert(std::pair<int,SDL_Surface*>(tt[i]->identifier,pom));
}
}
void CPlayerInterface::yourTurn()
@ -1584,83 +1531,13 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
}
void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
{
graphics.heroWins.erase(hero->ID);
graphics->heroWins.erase(hero->ID);
}
void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
{
if(graphics.heroWins.find(hero->subID)==graphics.heroWins.end())
graphics.heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero)));
if(graphics->heroWins.find(hero->subID)==graphics->heroWins.end())
graphics->heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero)));
}
SDL_Surface * CPlayerInterface::Graphics::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to)
{
char * buf = new char[10];
for (int i=from;i<to;i++)
{
itoa(curh->primSkills[i],buf,10);
printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
}
delete[] buf;
return ret;
}
SDL_Surface * CPlayerInterface::Graphics::drawHeroInfoWin(const CGHeroInstance * curh)
{
char * buf = new char[10];
SDL_Surface * ret = SDL_DisplayFormat(hInfo);
blueToPlayersAdv(hInfo,curh->tempOwner,1);
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
printAt(curh->name,75,15,GEOR13,zwykly,ret);
drawPrimarySkill(curh, ret);
for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
{
blitAt(LOCPLINT->graphics.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,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;
}
SDL_Surface * CPlayerInterface::Graphics::drawTownInfoWin(const CGTownInstance * curh)
{
char * buf = new char[10];
blueToPlayersAdv(tInfo,curh->tempOwner,1);
SDL_Surface * ret = SDL_DisplayFormat(tInfo);
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
printAt(curh->name,75,15,GEOR13,zwykly,ret);
int pom = curh->fortLevel() - 1; if(pom<0) pom = 3;
blitAt(forts->ourImages[pom].bitmap,115,42,ret);
if((pom=curh->hallLevel())>=0)
blitAt(halls->ourImages[pom].bitmap,77,42,ret);
itoa(curh->dailyIncome(),buf,10);
printAtMiddle(buf,167,70,GEORM,zwykly,ret);
for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
{
if(!i->second.first)
continue;
blitAt(LOCPLINT->graphics.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);
}
//blit town icon
pom = curh->subID*2;
if (!curh->hasFort())
pom += F_NUMBER*2;
if(curh->builded >= MAX_BUILDING_PER_TURN)
pom++;
blitAt(bigTownPic->ourImages[pom].bitmap,13,13,ret);
delete[] buf;
return ret;
}
void CPlayerInterface::openTownWindow(const CGTownInstance * town)
{
adventureInt->hide();
@ -1677,10 +1554,10 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe
switch (specific->ID)
{
case 34:
return graphics.drawHeroInfoWin(dynamic_cast<const CGHeroInstance*>(specific));
return graphics->drawHeroInfoWin(dynamic_cast<const CGHeroInstance*>(specific));
break;
case 98:
return graphics.drawTownInfoWin(dynamic_cast<const CGTownInstance*>(specific));
return graphics->drawTownInfoWin(dynamic_cast<const CGTownInstance*>(specific));
break;
default:
return NULL;
@ -1694,11 +1571,11 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe
case HEROI_TYPE:
{
const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
return graphics.drawHeroInfoWin(curh);
return graphics->drawHeroInfoWin(curh);
}
case TOWNI_TYPE:
{
return graphics.drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected);
return graphics->drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected);
}
default:
return NULL;
@ -1935,8 +1812,8 @@ int3 CPlayerInterface::repairScreenPos(int3 pos)
}
void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)
{
SDL_FreeSurface(graphics.heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia
graphics.heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki.
SDL_FreeSurface(graphics->heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia
graphics->heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki.
if (adventureInt->selection.selected == hero)
adventureInt->infoBar.draw();
return;
@ -1977,8 +1854,8 @@ void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
const CGHeroInstance * hh;
if(hh = dynamic_cast<const CGHeroInstance*>(obj))
{
SDL_FreeSurface(graphics.heroWins[hh->subID]);
graphics.heroWins[hh->subID] = infoWin(hh);
SDL_FreeSurface(graphics->heroWins[hh->subID]);
graphics->heroWins[hh->subID] = infoWin(hh);
}
CHeroWindow * hw = dynamic_cast<CHeroWindow *>(curint);
if(hw)
@ -1998,8 +1875,8 @@ void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
const CGTownInstance * tt;
if(tt = dynamic_cast<const CGTownInstance*>(obj))
{
SDL_FreeSurface(graphics.townWins[tt->identifier]);
graphics.townWins[tt->identifier] = infoWin(tt);
SDL_FreeSurface(graphics->townWins[tt->identifier]);
graphics->townWins[tt->identifier] = infoWin(tt);
}
const CCastleInterface *ci = dynamic_cast<CCastleInterface*>(curint);
@ -2406,7 +2283,7 @@ void CHeroList::clickRight(tribool down)
}
//show popup
CInfoPopup * ip = new CInfoPopup(LOCPLINT->graphics.heroWins[items[from+ny].first->subID],LOCPLINT->current->motion.x-LOCPLINT->graphics.heroWins[items[from+ny].first->subID]->w,LOCPLINT->current->motion.y-LOCPLINT->graphics.heroWins[items[from+ny].first->subID]->h,false);
CInfoPopup * ip = new CInfoPopup(graphics->heroWins[items[from+ny].first->subID],LOCPLINT->current->motion.x-graphics->heroWins[items[from+ny].first->subID]->w,LOCPLINT->current->motion.y-graphics->heroWins[items[from+ny].first->subID]->h,false);
ip->activate();
}
else
@ -2459,7 +2336,7 @@ void CHeroList::draw()
if (pom>25) pom=25;
if (pom<0) pom=0;
blitAt(mana->ourImages[pom].bitmap,posmanx,posmany+i*32); //mana
SDL_Surface * temp = LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->type->portraitSmall;
SDL_Surface * temp = graphics->portraitSmall[LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->subID];
blitAt(temp,posporx,pospory+i*32);
if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE))
{
@ -2646,7 +2523,7 @@ void CTownList::clickRight(tribool down)
}
//show popup
CInfoPopup * ip = new CInfoPopup(LOCPLINT->graphics.townWins[items[from+ny]->identifier],LOCPLINT->current->motion.x-LOCPLINT->graphics.townWins[items[from+ny]->identifier]->w,LOCPLINT->current->motion.y-LOCPLINT->graphics.townWins[items[from+ny]->identifier]->h,false);
CInfoPopup * ip = new CInfoPopup(graphics->townWins[items[from+ny]->identifier],LOCPLINT->current->motion.x-graphics->townWins[items[from+ny]->identifier]->w,LOCPLINT->current->motion.y-graphics->townWins[items[from+ny]->identifier]->h,false);
ip->activate();
}
else
@ -2671,15 +2548,15 @@ void CTownList::draw()
int i = iT-from;
if (iT>=items.size())
{
blitAt(CGI->townh->getPic(-1),posporx,pospory+i*32);
blitAt(graphics->getPic(-1),posporx,pospory+i*32);
continue;
}
blitAt(CGI->townh->getPic(items[iT]->subID,items[iT]->hasFort(),items[iT]->builded),posporx,pospory+i*32);
blitAt(graphics->getPic(items[iT]->subID,items[iT]->hasFort(),items[iT]->builded),posporx,pospory+i*32);
if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE))
{
blitAt(CGI->townh->getPic(-2),posporx,pospory+i*32);
blitAt(graphics->getPic(-2),posporx,pospory+i*32);
}
}
if (from>0)
@ -2705,7 +2582,7 @@ CCreaturePic::~CCreaturePic()
}
int CCreaturePic::blitPic(SDL_Surface *to, int x, int y, bool nextFrame)
{
blitAt(LOCPLINT->graphics.backgrounds[c->faction],x,y);//curx-50,pos.y+130-65);
blitAt(graphics->backgrounds[c->faction],x,y);//curx-50,pos.y+130-65);
SDL_Rect dst = genRect(130,100,x,y);
if(c->isDoubleWide())
x-=15;
@ -2804,8 +2681,8 @@ void CRecrutationWindow::show(SDL_Surface * to)
int curx = pos.x+115-creatures[which].res.size()*16;
for(int i=0;i<creatures[which].res.size();i++)
{
blitAt(CGI->townh->resources->ourImages[creatures[which].res[i].first].bitmap,curx,pos.y+243,screen);
blitAt(CGI->townh->resources->ourImages[creatures[which].res[i].first].bitmap,curx+258,pos.y+243,screen);
blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx,pos.y+243,screen);
blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx+258,pos.y+243,screen);
itoa(creatures[which].res[i].second,pom,10);
printAtMiddle(pom,curx+12,pos.y+286,GEOR13,zwykly,screen);
itoa(creatures[which].res[i].second * slider->value,pom,10);
@ -3069,8 +2946,8 @@ CCreInfoWindow::CCreInfoWindow
//luck and morale
blitAt(LOCPLINT->graphics.morale42->ourImages[(State)?(State->morale+3):(3)].bitmap,24,189,bitmap);
blitAt(LOCPLINT->graphics.luck42->ourImages[(State)?(State->luck+3):(3)].bitmap,77,189,bitmap);
blitAt(graphics->morale42->ourImages[(State)?(State->morale+3):(3)].bitmap,24,189,bitmap);
blitAt(graphics->luck42->ourImages[(State)?(State->luck+3):(3)].bitmap,77,189,bitmap);
//print abilities text - if r-click popup
if(type)

View File

@ -311,31 +311,6 @@ public:
std::vector<TimeInterested*> timeinterested;
std::vector<IShowable*> objsToBlit;
//various graphics
class Graphics
{
public:
//various graphics
SDL_Surface * hInfo, *tInfo; //hero and town infobox bgs
std::vector<std::pair<int, int> > slotsPos; //creature slot positions in infoboxes
CDefEssential *luck22, *luck30, *luck42, *luck82,
*morale22, *morale30, *morale42, *morale82,
*halls, *forts, *bigTownPic;
std::map<int,SDL_Surface*> heroWins; //hero_ID => infobox
std::map<int,SDL_Surface*> townWins; //town_ID => infobox
CDefHandler * artDefs; //artifacts
//creatures
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::map<int,SDL_Surface*> bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border
std::map<int,SDL_Surface*> backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral
//functions
Graphics();
SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh);
SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS);
SDL_Surface * drawTownInfoWin(const CGTownInstance * curh);
} graphics;
//overloaded funcs from CGameInterface
void yourTurn();
void heroMoved(const HeroMoveDetails & details);

Binary file not shown.

469
client/Graphics.cpp Normal file
View File

@ -0,0 +1,469 @@
#include "../stdafx.h"
#include "Graphics.h"
#include "../hch/CDefHandler.h"
#include "../hch/CObjectHandler.h"
#include "../SDL_Extensions.h"
using namespace CSDL_Ext;
Graphics * graphics = NULL;
SDL_Surface * Graphics::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to)
{
char * buf = new char[10];
for (int i=from;i<to;i++)
{
itoa(curh->primSkills[i],buf,10);
printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
}
delete[] buf;
return ret;
}
SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh)
{
char * buf = new char[10];
SDL_Surface * ret = SDL_DisplayFormat(hInfo);
blueToPlayersAdv(hInfo,curh->tempOwner,1);
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
printAt(curh->name,75,15,GEOR13,zwykly,ret);
drawPrimarySkill(curh, ret);
for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
{
blitAt(graphics->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(graphics->portraitLarge[curh->subID],11,12,ret);
itoa(curh->mana,buf,10);
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;
}
SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh)
{
char * buf = new char[10];
blueToPlayersAdv(tInfo,curh->tempOwner,1);
SDL_Surface * ret = SDL_DisplayFormat(tInfo);
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
printAt(curh->name,75,15,GEOR13,zwykly,ret);
int pom = curh->fortLevel() - 1; if(pom<0) pom = 3;
blitAt(forts->ourImages[pom].bitmap,115,42,ret);
if((pom=curh->hallLevel())>=0)
blitAt(halls->ourImages[pom].bitmap,77,42,ret);
itoa(curh->dailyIncome(),buf,10);
printAtMiddle(buf,167,70,GEORM,zwykly,ret);
for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
{
if(!i->second.first)
continue;
blitAt(graphics->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);
}
//blit town icon
pom = curh->subID*2;
if (!curh->hasFort())
pom += F_NUMBER*2;
if(curh->builded >= MAX_BUILDING_PER_TURN)
pom++;
blitAt(bigTownPic->ourImages[pom].bitmap,13,13,ret);
delete[] buf;
return ret;
}
Graphics::Graphics()
{
artDefs = CDefHandler::giveDef("ARTIFACT.DEF");
hInfo = BitmapHandler::loadBitmap("HEROQVBK.bmp");
SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255));
tInfo = BitmapHandler::loadBitmap("TOWNQVBK.bmp");
SDL_SetColorKey(tInfo,SDL_SRCCOLORKEY,SDL_MapRGB(tInfo->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 = CDefHandler::giveDefEss("ILCK22.DEF");
luck30 = CDefHandler::giveDefEss("ILCK30.DEF");
luck42 = CDefHandler::giveDefEss("ILCK42.DEF");
luck82 = CDefHandler::giveDefEss("ILCK82.DEF");
morale22 = CDefHandler::giveDefEss("IMRL22.DEF");
morale30 = CDefHandler::giveDefEss("IMRL30.DEF");
morale42 = CDefHandler::giveDefEss("IMRL42.DEF");
morale82 = CDefHandler::giveDefEss("IMRL82.DEF");
halls = CDefHandler::giveDefEss("ITMTLS.DEF");
forts = CDefHandler::giveDefEss("ITMCLS.DEF");
bigTownPic = CDefHandler::giveDefEss("ITPT.DEF");
std::ifstream ifs;
ifs.open("config/cr_bgs.txt");
while(!ifs.eof())
{
int id;
std::string name;
ifs >> id >> name;
backgrounds[id]=BitmapHandler::loadBitmap(name);
}
ifs.close();
ifs.clear();
//loading 32x32px imgs
CDefHandler *smi = CDefHandler::giveDef("CPRSMALL.DEF");
smi->notFreeImgs = true;
for (int i=0; i<smi->ourImages.size(); i++)
{
smallImgs[i-2] = smi->ourImages[i].bitmap;
}
delete smi;
smi = CDefHandler::giveDef("TWCRPORT.DEF");
smi->notFreeImgs = true;
for (int i=0; i<smi->ourImages.size(); i++)
{
bigImgs[i-2] = smi->ourImages[i].bitmap;
}
delete smi;
std::ifstream of("config/portrety.txt");
for (int j=0;j<HEROES_QUANTITY;j++)
{
int ID;
of>>ID;
std::string path;
of>>path;
portraitSmall.push_back(BitmapHandler::loadBitmap(path));
//if (!heroes[ID]->portraitSmall)
// std::cout<<"Can't read small portrait for "<<ID<<" ("<<path<<")\n";
for(int ff=0; ff<path.size(); ++ff) //size letter is usually third one, but there are exceptions an it should fix the problem
{
if(path[ff]=='S')
{
path[ff]='L';
break;
}
}
portraitLarge.push_back(BitmapHandler::loadBitmap(path));
//if (!heroes[ID]->portraitLarge)
// std::cout<<"Can't read large portrait for "<<ID<<" ("<<path<<")\n";
SDL_SetColorKey(portraitLarge[portraitLarge.size()-1],SDL_SRCCOLORKEY,SDL_MapRGB(portraitLarge[portraitLarge.size()-1]->format,0,255,255));
}
of.close();
pskillsb = CDefHandler::giveDef("PSKILL.DEF");
resources = CDefHandler::giveDef("RESOUR82.DEF");
un44 = CDefHandler::giveDef("UN44.DEF");
smallIcons = CDefHandler::giveDef("ITPA.DEF");
resources32 = CDefHandler::giveDef("RESOURCE.DEF");
loadHeroFlags();
}
void Graphics::loadHeroFlags()
{
flags1.push_back(CDefHandler::giveDef("ABF01L.DEF")); //red
flags1.push_back(CDefHandler::giveDef("ABF01G.DEF")); //blue
flags1.push_back(CDefHandler::giveDef("ABF01R.DEF")); //tan
flags1.push_back(CDefHandler::giveDef("ABF01D.DEF")); //green
flags1.push_back(CDefHandler::giveDef("ABF01B.DEF")); //orange
flags1.push_back(CDefHandler::giveDef("ABF01P.DEF")); //purple
flags1.push_back(CDefHandler::giveDef("ABF01W.DEF")); //teal
flags1.push_back(CDefHandler::giveDef("ABF01K.DEF")); //pink
for(int q=0; q<8; ++q)
{
for(int o=0; o<flags1[q]->ourImages.size(); ++o)
{
if(flags1[q]->ourImages[o].groupNumber==6)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.imName = std::string();
flags1[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags1[q]->ourImages[o].groupNumber==7)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap);
nci.groupNumber = 11;
nci.imName = std::string();
flags1[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags1[q]->ourImages[o].groupNumber==8)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap);
nci.groupNumber = 12;
nci.imName = std::string();
flags1[q]->ourImages.push_back(nci);
}
o+=8;
}
}
for(int ff=0; ff<flags1[q]->ourImages.size(); ++ff)
{
SDL_SetColorKey(flags1[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB(flags1[q]->ourImages[ff].bitmap->format, 0, 255, 255)
);
}
flags1[q]->alphaTransformed = true;
}
flags2.push_back(CDefHandler::giveDef("ABF02L.DEF")); //red
flags2.push_back(CDefHandler::giveDef("ABF02G.DEF")); //blue
flags2.push_back(CDefHandler::giveDef("ABF02R.DEF")); //tan
flags2.push_back(CDefHandler::giveDef("ABF02D.DEF")); //green
flags2.push_back(CDefHandler::giveDef("ABF02B.DEF")); //orange
flags2.push_back(CDefHandler::giveDef("ABF02P.DEF")); //purple
flags2.push_back(CDefHandler::giveDef("ABF02W.DEF")); //teal
flags2.push_back(CDefHandler::giveDef("ABF02K.DEF")); //pink
for(int q=0; q<8; ++q)
{
for(int o=0; o<flags2[q]->ourImages.size(); ++o)
{
if(flags2[q]->ourImages[o].groupNumber==6)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.imName = std::string();
flags2[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags2[q]->ourImages[o].groupNumber==7)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap);
nci.groupNumber = 11;
nci.imName = std::string();
flags2[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags2[q]->ourImages[o].groupNumber==8)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap);
nci.groupNumber = 12;
nci.imName = std::string();
flags2[q]->ourImages.push_back(nci);
}
o+=8;
}
}
for(int ff=0; ff<flags2[q]->ourImages.size(); ++ff)
{
SDL_SetColorKey(flags2[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB(flags2[q]->ourImages[ff].bitmap->format, 0, 255, 255)
);
}
flags2[q]->alphaTransformed = true;
}
flags3.push_back(CDefHandler::giveDef("ABF03L.DEF")); //red
flags3.push_back(CDefHandler::giveDef("ABF03G.DEF")); //blue
flags3.push_back(CDefHandler::giveDef("ABF03R.DEF")); //tan
flags3.push_back(CDefHandler::giveDef("ABF03D.DEF")); //green
flags3.push_back(CDefHandler::giveDef("ABF03B.DEF")); //orange
flags3.push_back(CDefHandler::giveDef("ABF03P.DEF")); //purple
flags3.push_back(CDefHandler::giveDef("ABF03W.DEF")); //teal
flags3.push_back(CDefHandler::giveDef("ABF03K.DEF")); //pink
for(int q=0; q<8; ++q)
{
for(int o=0; o<flags3[q]->ourImages.size(); ++o)
{
if(flags3[q]->ourImages[o].groupNumber==6)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.imName = std::string();
flags3[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags3[q]->ourImages[o].groupNumber==7)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap);
nci.groupNumber = 11;
nci.imName = std::string();
flags3[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags3[q]->ourImages[o].groupNumber==8)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap);
nci.groupNumber = 12;
nci.imName = std::string();
flags3[q]->ourImages.push_back(nci);
}
o+=8;
}
}
for(int ff=0; ff<flags3[q]->ourImages.size(); ++ff)
{
SDL_SetColorKey(flags3[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB(flags3[q]->ourImages[ff].bitmap->format, 0, 255, 255)
);
}
flags3[q]->alphaTransformed = true;
}
flags4.push_back(CDefHandler::giveDef("AF00.DEF")); //red
flags4.push_back(CDefHandler::giveDef("AF01.DEF")); //blue
flags4.push_back(CDefHandler::giveDef("AF02.DEF")); //tan
flags4.push_back(CDefHandler::giveDef("AF03.DEF")); //green
flags4.push_back(CDefHandler::giveDef("AF04.DEF")); //orange
flags4.push_back(CDefHandler::giveDef("AF05.DEF")); //purple
flags4.push_back(CDefHandler::giveDef("AF06.DEF")); //teal
flags4.push_back(CDefHandler::giveDef("AF07.DEF")); //pink
for(int q=0; q<8; ++q)
{
for(int o=0; o<flags4[q]->ourImages.size(); ++o)
{
if(flags4[q]->ourImages[o].groupNumber==6)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.imName = std::string();
flags4[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags4[q]->ourImages[o].groupNumber==7)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.groupNumber = 11;
nci.imName = std::string();
flags4[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags4[q]->ourImages[o].groupNumber==8)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.groupNumber = 12;
nci.imName = std::string();
flags4[q]->ourImages.push_back(nci);
}
o+=8;
}
}
for(int o=0; o<flags4[q]->ourImages.size(); ++o)
{
if(flags4[q]->ourImages[o].groupNumber==1)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.groupNumber = 13;
nci.imName = std::string();
flags4[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags4[q]->ourImages[o].groupNumber==2)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.groupNumber = 14;
nci.imName = std::string();
flags4[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags4[q]->ourImages[o].groupNumber==3)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.groupNumber = 15;
nci.imName = std::string();
flags4[q]->ourImages.push_back(nci);
}
o+=8;
}
}
for(int ff=0; ff<flags4[q]->ourImages.size(); ++ff)
{
SDL_SetColorKey(flags4[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB(flags4[q]->ourImages[ff].bitmap->format, 0, 255, 255)
);
}
flags4[q]->alphaTransformed = true;
}
}
SDL_Surface * Graphics::getPic(int ID, bool fort, bool builded)
{
if (ID==-1)
return smallIcons->ourImages[0].bitmap;
else if (ID==-2)
return smallIcons->ourImages[1].bitmap;
else if (ID==-3)
return smallIcons->ourImages[2+F_NUMBER*4].bitmap;
else if (ID>F_NUMBER || ID<-3)
throw new std::exception("Invalid ID");
else
{
int pom = 3;
if(!fort)
pom+=F_NUMBER*2;
pom += ID*2;
if (!builded)
pom--;
return smallIcons->ourImages[pom].bitmap;
}
}

40
client/Graphics.h Normal file
View File

@ -0,0 +1,40 @@
#pragma once
#include "../global.h"
class CDefEssential;
struct SDL_Surface;
class CGHeroInstance;
class CGTownInstance;
class CDefHandler;
class Graphics
{
public:
//various graphics
SDL_Surface * hInfo, *tInfo; //hero and town infobox bgs
std::vector<std::pair<int, int> > slotsPos; //creature slot positions in infoboxes
CDefEssential *luck22, *luck30, *luck42, *luck82,
*morale22, *morale30, *morale42, *morale82,
*halls, *forts, *bigTownPic;
std::map<int,SDL_Surface*> heroWins; //hero_ID => infobox
std::map<int,SDL_Surface*> townWins; //town_ID => infobox
CDefHandler * artDefs; //artifacts
std::vector<SDL_Surface *> portraitSmall; //48x32 px portraits of heroes
std::vector<SDL_Surface *> portraitLarge; //58x64 px portraits of heroes
std::vector<CDefHandler *> flags1, flags2, flags3, flags4; //flags blitted on heroes when ,
CDefHandler * pskillsb, *resources; //82x93
CDefHandler * un44; //many things
CDefHandler * smallIcons, *resources32; //resources 32x32
//creatures
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::map<int,SDL_Surface*> bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border
std::map<int,SDL_Surface*> backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral
//functions
Graphics();
void loadHeroFlags();
SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh);
SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS);
SDL_Surface * drawTownInfoWin(const CGTownInstance * curh);
SDL_Surface * getPic(int ID, bool fort=true, bool builded=false); //returns small picture of town: ID=-1 - blank; -2 - border; -3 - random
};
extern Graphics * graphics;

View File

@ -12,15 +12,15 @@ void CAbilityHandler::loadAbilities()
std::string dump;
for(int i=0; i<2; ++i)
{
CGeneralTextHandler::loadToIt(dump,buf,it,3);
loadToIt(dump,buf,it,3);
}
for (int i=0; i<SKILL_QUANTITY; i++)
{
CAbility * nab = new CAbility; //new skill, that will be read
CGeneralTextHandler::loadToIt(nab->name,buf,it,4);
CGeneralTextHandler::loadToIt(nab->basicText,buf,it,4);
CGeneralTextHandler::loadToIt(nab->advText,buf,it,4);
CGeneralTextHandler::loadToIt(nab->expText,buf,it,3);
loadToIt(nab->name,buf,it,4);
loadToIt(nab->basicText,buf,it,4);
loadToIt(nab->advText,buf,it,4);
loadToIt(nab->expText,buf,it,3);
nab->idNumber = abilities.size();
abilities.push_back(nab);
}
@ -33,7 +33,7 @@ void CAbilityHandler::loadAbilities()
for(int i=0; i<6; ++i)
{
std::string buffo;
CGeneralTextHandler::loadToIt(buffo,buf,it,3);
loadToIt(buffo,buf,it,3);
levels.push_back(buffo);
}
}

View File

@ -1,144 +1,42 @@
#define VCMI_DLL
#include "../stdafx.h"
#include "CArtHandler.h"
#include "../CGameInfo.h"
#include "CGeneralTextHandler.h"
#include "CLodHandler.h"
#include <boost/assign/std/vector.hpp>
#include <boost/assign/list_of.hpp>
void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
extern CLodHandler *bitmaph;
using namespace boost::assign;
void CArtHandler::loadArtifacts()
{
std::string buf = CGI->bitmaph->getTextFile("ARTRAITS.TXT");
std::vector<bool CArtifact::*> slots;
slots += &CArtifact::spellBook, &CArtifact::warMachine4, &CArtifact::warMachine3, &CArtifact::warMachine2,
&CArtifact::warMachine1, &CArtifact::misc5, &CArtifact::misc4, &CArtifact::misc3, &CArtifact::misc2,
&CArtifact::misc1, &CArtifact::feet, &CArtifact::lRing, &CArtifact::rRing, &CArtifact::torso,
&CArtifact::lHand, &CArtifact::rHand, &CArtifact::neck, &CArtifact::shoulders, &CArtifact::head;
std::map<char,EartClass> classes =
map_list_of('S',SartClass)('T',TartClass)('N',NartClass)('J',JartClass)('R',RartClass);
std::string buf = bitmaph->getTextFile("ARTRAITS.TXT"), dump, pom;
int it=0;
std::string dump;
for(int i=0; i<2; ++i)
{
CGeneralTextHandler::loadToIt(dump,buf,it,3);
loadToIt(dump,buf,it,3);
}
for (int i=0; i<ARTIFACTS_QUANTITY; i++)
{
CArtifact nart;
std::string pom;
CGeneralTextHandler::loadToIt(nart.name,buf,it,4);
CGeneralTextHandler::loadToIt(pom,buf,it,4);
loadToIt(nart.name,buf,it,4);
loadToIt(pom,buf,it,4);
nart.price=atoi(pom.c_str());
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.spellBook=true;
else
nart.spellBook = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.warMachine4=true;
else
nart.warMachine4 = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.warMachine3=true;
else
nart.warMachine3 = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.warMachine2=true;
else
nart.warMachine2 = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.warMachine1=true;
else
nart.warMachine1 = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.misc5=true;
else
nart.misc5 = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.misc4=true;
else
nart.misc4 = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.misc3=true;
else
nart.misc3 = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.misc2=true;
else
nart.misc2 = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.misc1=true;
else
nart.misc1 = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.feet=true;
else
nart.feet = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.lRing=true;
else
nart.lRing = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.rRing=true;
else
nart.rRing = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.torso=true;
else
nart.torso = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.lHand=true;
else
nart.lHand = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.rHand=true;
else
nart.rHand = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.neck=true;
else
nart.neck = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.shoulders=true;
else
nart.shoulders = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
if (pom[0]=='x')
nart.head=true;
else
nart.head = false;
CGeneralTextHandler::loadToIt(pom,buf,it,4);
switch (pom[0])
for(int j=0;j<slots.size();j++)
{
case 'S':
nart.aClass=SartClass;
break;
case 'T':
nart.aClass=TartClass;
break;
case 'N':
nart.aClass=NartClass;
break;
case 'J':
nart.aClass=JartClass;
break;
case 'R':
nart.aClass=RartClass;
break;
loadToIt(pom,buf,it,4);
nart.*slots[j] = (pom[0]=='x');
}
CGeneralTextHandler::loadToIt(nart.description,buf,it,3);
nart.id=artifacts.size();
loadToIt(pom,buf,it,4);
nart.aClass = classes[pom[0]];
loadToIt(nart.description,buf,it,3);
nart.id=i;
artifacts.push_back(nart);
}
for(int i=0;i<144;i++) //do 144, bo nie chcemy bzdurek

View File

@ -1,13 +1,13 @@
#ifndef CARTHANDLER_H
#define CARTHANDLER_H
#include "../global.h"
#include <string>
#include <vector>
enum EartClass {SartClass=0, TartClass, NartClass, JartClass, RartClass}; //artifact class (relict, treasure, strong, weak etc.)
class CDefHandler;
class CArtifact //container for artifacts
class DLL_EXPORT CArtifact //container for artifacts
{
public:
bool isAllowed; //true if we can use this artifact (map information)
@ -21,7 +21,7 @@ public:
int id;
};
class CArtHandler //handles artifacts
class DLL_EXPORT CArtHandler //handles artifacts
{
public:
std::vector<CArtifact*> treasures, minors, majors, relics;

View File

@ -28,7 +28,7 @@ void CGeneralTextHandler::load()
while(itr<strs.length()-1)
{
std::string tmp;
CGeneralTextHandler::loadToIt(tmp, strs, itr, 3);
loadToIt(tmp, strs, itr, 3);
arraytxt.push_back(tmp);
}
@ -37,7 +37,7 @@ void CGeneralTextHandler::load()
for(int hh=0; hh<4; ++hh)
{
std::string tmp;
CGeneralTextHandler::loadToIt(tmp, strin, itr, 3);
loadToIt(tmp, strin, itr, 3);
primarySkillNames.push_back(tmp);
}
@ -46,7 +46,7 @@ void CGeneralTextHandler::load()
for(int hh=0; hh<45; ++hh)
{
std::string tmp;
CGeneralTextHandler::loadToIt(tmp, strin2, itr, 3);
loadToIt(tmp, strin2, itr, 3);
jktexts.push_back(tmp);
}
@ -55,116 +55,7 @@ void CGeneralTextHandler::load()
for(int hh=0; hh<33; ++hh)
{
std::string tmp;
CGeneralTextHandler::loadToIt(tmp, strin3, itr, 3);
loadToIt(tmp, strin3, itr, 3);
heroscrn.push_back(tmp);
}
}
void CGeneralTextHandler::loadToIt(std::string &dest, std::string &src, int &iter, int mode)
{
switch(mode)
{
case 0:
{
int hmcr = 0;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\t')
++hmcr;
if(hmcr==1)
break;
}
++iter;
int befi=iter;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\t')
break;
}
dest = src.substr(befi, iter-befi);
++iter;
hmcr = 0;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\r')
++hmcr;
if(hmcr==1)
break;
}
iter+=2;
break;
}
case 1:
{
int hmcr = 0;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\t')
++hmcr;
if(hmcr==1)
break;
}
++iter;
int befi=iter;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\r')
break;
}
dest = src.substr(befi, iter-befi);
iter+=2;
break;
}
case 2:
{
int befi=iter;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\t')
break;
}
dest = src.substr(befi, iter-befi);
++iter;
int hmcr = 0;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\r')
++hmcr;
if(hmcr==1)
break;
}
iter+=2;
break;
}
case 3:
{
int befi=iter;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\r')
break;
}
dest = src.substr(befi, iter-befi);
iter+=2;
break;
}
case 4:
{
int befi=iter;
for(iter; iter<src.size(); ++iter)
{
if(src[iter]=='\t')
break;
}
dest = src.substr(befi, iter-befi);
iter++;
break;
}
}
}
}

View File

@ -1,9 +1,9 @@
#ifndef CGENERALTEXTHANDLER_H
#define CGENERALTEXTHANDLER_H
#include "../global.h"
#include <string>
#include <vector>
DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
class CGeneralTextHandler //Handles general texts
{
public:
@ -13,21 +13,6 @@ public:
std::vector<std::string> primarySkillNames;
std::vector<std::string> jktexts;
std::vector<std::string> heroscrn;
/*std::string cantAddManager, experienceLimitScenarioReached, heroExperienceInfo, perDay, or, somethingVanquished, lastTownLostInfo, heroesAbandonedYou, heroesAbandonedHim;
std::string couldNotSaveGame, errorOpeningFile, newgameUppercase, sureToDismissArmy, playersTurn, errorReceivingDataKeepTrying, somethingTheSomething, recruit, noRoomInGarrision, numberOFAdventuringHeroes, heroWithoutCreatures;
std::string videoQuality, itemCantBeTraded, sureDismissHero, selectSpellTarget, invalidTeleportDestination, teleportHere, castSomething, castSomethingOnSomething, sureRetreat, notEnoughGold, capturedEnemyArtifact, none;
std::string surrenderProposal, highMoraleNextAttack, lowMoraleFreeze, makeRoomInArmyForSomething, attackSomethingSomethingDamage, shootSomethingOneShootLeftSomethingDamage;
std::string campaignDescription, somethingIsActive, sessionName, userName, creature, creatures, badLuckOnSomething, goodLuckOnSomething, treasure, somethingSomethingsUnderAttack, town, hero, townScreen, cannotBuildBoat, requires, systemUppercase;
std::string worldMapHelp, sureEndTurnHeroMayMove, diggingArtifactWholeDay, noRoomForArtifact, heroUncoveredThe, diggingNothing, tryLookingOnLand, unchartedTerritory;
std::string month, week, day, enemyViewTip, pingInfo, sureToRestart, sureToStartNewGame, sureQuit, dimensionDoorFiled, chooseBonus, ping, pingSomething, pingEveryone, score, autosaveUppercase;
std::string startingHeroB, heroSpecialityB, associatedCreaturesB, townAlignmentB, errorSendingDataKeepTrying, tooFewPalyersForMultiGame, artifactBonusB, goldBonusB, resourceBonusB, randomBonusB;
std::string fiveHundredToOneThousand, armageddonDamages, woodOreBonus, randomlyChoosenArtifact, disruptingRayReducesDefence, goldStartingBonus, woodOreStartingBonus, randomStartingBonus;
std::string youEliminatedFormGame, scoreToHallOfFame, trySearchingOnClearGround, sendingData, receivingData, chaosMp2, randomHeroB, randomStartingHeroInfo, randomTownB, randomStartingTownInfo, somethingSurrendersInfo;
std::string heroesCDNotFound, autosaving, playerexitUppercase, statusWindowTip, border, somethingAbsorbsMana, somethingsAbsorbMana, unableChangeHeroesDirectory, unableFindHeoresDataFiles, victoryAchievementText;
std::string somethingsRiseFromDeath, somethingRisesFormDeath, somethingDiesUnderGaze, somethingsDieUnderGaze, somethingTakesDefensiveStance, somethingsTakeDefensiveStance, somethingExp, nearestTownOccupied, noAvailableTown, heroTooTiredSpell, townGateCannotBeUsed, youHaveNoHeroes, heroHasCastSpell;
std::string doYouWishToSaveSomethingsArmy, problemsWithInputDevices, problemsWithSound, problemsWithMouse, problemsWithWindows, abandonedShipyard, spellFailed, somethingPauses, somethingsPause, somethingLevelSomething, somethingStudiedMagic, learnsSpeced, andSpaced, fromSomethingSpaced;*/
static void loadToIt(std::string & dest, std::string & src, int & iter, int mode = 0); //mode 0 - dump to tab, dest to tab, dump to eol //mode 1 - dump to tab, src to eol //mode 2 - copy to tab, dump to eol //mode 3 - copy to eol //mode 4 - copy to tab
void load();
};

View File

@ -1,361 +1,34 @@
#include "../stdafx.h"
#include "CHeroHandler.h"
#include "../CGameInfo.h"
#include <sstream>
#include "../CGameInfo.h"
#include "CGeneralTextHandler.h"
#include "CLodHandler.h"
#include "CAbilityHandler.h"
#include "../SDL_Extensions.h"
#include <cmath>
#include <iomanip>
#include "CDefHandler.h"
extern CLodHandler * bitmaph;
void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
CHeroHandler::~CHeroHandler()
{
for (int j=0;j<heroes.size();j++)
{
if (heroes[j]->portraitSmall)
SDL_FreeSurface(heroes[j]->portraitSmall);
delete heroes[j];
}
}
{}
void CHeroHandler::loadPortraits()
{
std::ifstream of("config/portrety.txt");
for (int j=0;j<heroes.size();j++)
{
int ID;
of>>ID;
std::string path;
of>>path;
heroes[ID]->portraitSmall=BitmapHandler::loadBitmap(path);
if (!heroes[ID]->portraitSmall)
std::cout<<"Can't read small portrait for "<<ID<<" ("<<path<<")\n";
for(int ff=0; ff<path.size(); ++ff) //size letter is usually third one, but there are exceptions an it should fix the problem
{
if(path[ff]=='S')
{
path[ff]='L';
break;
}
}
heroes[ID]->portraitLarge=BitmapHandler::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();
pskillsb = CDefHandler::giveDef("PSKILL.DEF");
resources = CDefHandler::giveDef("RESOUR82.DEF");
un44 = CDefHandler::giveDef("UN44.DEF");
std::string strs = CGI->bitmaph->getTextFile("PRISKILL.TXT");
std::string strs = bitmaph->getTextFile("PRISKILL.TXT");
int itr=0;
for (int i=0; i<PRIMARY_SKILLS; i++)
{
std::string tmp;
CGeneralTextHandler::loadToIt(tmp, strs, itr, 3);
loadToIt(tmp, strs, itr, 3);
pskillsn.push_back(tmp);
}
}
void CHeroHandler::loadHeroFlags()
{
flags1.push_back(CDefHandler::giveDef("ABF01L.DEF")); //red
flags1.push_back(CDefHandler::giveDef("ABF01G.DEF")); //blue
flags1.push_back(CDefHandler::giveDef("ABF01R.DEF")); //tan
flags1.push_back(CDefHandler::giveDef("ABF01D.DEF")); //green
flags1.push_back(CDefHandler::giveDef("ABF01B.DEF")); //orange
flags1.push_back(CDefHandler::giveDef("ABF01P.DEF")); //purple
flags1.push_back(CDefHandler::giveDef("ABF01W.DEF")); //teal
flags1.push_back(CDefHandler::giveDef("ABF01K.DEF")); //pink
for(int q=0; q<8; ++q)
{
for(int o=0; o<flags1[q]->ourImages.size(); ++o)
{
if(flags1[q]->ourImages[o].groupNumber==6)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.imName = std::string();
flags1[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags1[q]->ourImages[o].groupNumber==7)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap);
nci.groupNumber = 11;
nci.imName = std::string();
flags1[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags1[q]->ourImages[o].groupNumber==8)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags1[q]->ourImages[o+e].bitmap);
nci.groupNumber = 12;
nci.imName = std::string();
flags1[q]->ourImages.push_back(nci);
}
o+=8;
}
}
for(int ff=0; ff<flags1[q]->ourImages.size(); ++ff)
{
SDL_SetColorKey(flags1[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB(flags1[q]->ourImages[ff].bitmap->format, 0, 255, 255)
);
}
flags1[q]->alphaTransformed = true;
}
flags2.push_back(CDefHandler::giveDef("ABF02L.DEF")); //red
flags2.push_back(CDefHandler::giveDef("ABF02G.DEF")); //blue
flags2.push_back(CDefHandler::giveDef("ABF02R.DEF")); //tan
flags2.push_back(CDefHandler::giveDef("ABF02D.DEF")); //green
flags2.push_back(CDefHandler::giveDef("ABF02B.DEF")); //orange
flags2.push_back(CDefHandler::giveDef("ABF02P.DEF")); //purple
flags2.push_back(CDefHandler::giveDef("ABF02W.DEF")); //teal
flags2.push_back(CDefHandler::giveDef("ABF02K.DEF")); //pink
for(int q=0; q<8; ++q)
{
for(int o=0; o<flags2[q]->ourImages.size(); ++o)
{
if(flags2[q]->ourImages[o].groupNumber==6)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.imName = std::string();
flags2[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags2[q]->ourImages[o].groupNumber==7)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap);
nci.groupNumber = 11;
nci.imName = std::string();
flags2[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags2[q]->ourImages[o].groupNumber==8)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags2[q]->ourImages[o+e].bitmap);
nci.groupNumber = 12;
nci.imName = std::string();
flags2[q]->ourImages.push_back(nci);
}
o+=8;
}
}
for(int ff=0; ff<flags2[q]->ourImages.size(); ++ff)
{
SDL_SetColorKey(flags2[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB(flags2[q]->ourImages[ff].bitmap->format, 0, 255, 255)
);
}
flags2[q]->alphaTransformed = true;
}
flags3.push_back(CDefHandler::giveDef("ABF03L.DEF")); //red
flags3.push_back(CDefHandler::giveDef("ABF03G.DEF")); //blue
flags3.push_back(CDefHandler::giveDef("ABF03R.DEF")); //tan
flags3.push_back(CDefHandler::giveDef("ABF03D.DEF")); //green
flags3.push_back(CDefHandler::giveDef("ABF03B.DEF")); //orange
flags3.push_back(CDefHandler::giveDef("ABF03P.DEF")); //purple
flags3.push_back(CDefHandler::giveDef("ABF03W.DEF")); //teal
flags3.push_back(CDefHandler::giveDef("ABF03K.DEF")); //pink
for(int q=0; q<8; ++q)
{
for(int o=0; o<flags3[q]->ourImages.size(); ++o)
{
if(flags3[q]->ourImages[o].groupNumber==6)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.imName = std::string();
flags3[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags3[q]->ourImages[o].groupNumber==7)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap);
nci.groupNumber = 11;
nci.imName = std::string();
flags3[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags3[q]->ourImages[o].groupNumber==8)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags3[q]->ourImages[o+e].bitmap);
nci.groupNumber = 12;
nci.imName = std::string();
flags3[q]->ourImages.push_back(nci);
}
o+=8;
}
}
for(int ff=0; ff<flags3[q]->ourImages.size(); ++ff)
{
SDL_SetColorKey(flags3[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB(flags3[q]->ourImages[ff].bitmap->format, 0, 255, 255)
);
}
flags3[q]->alphaTransformed = true;
}
flags4.push_back(CDefHandler::giveDef("AF00.DEF")); //red
flags4.push_back(CDefHandler::giveDef("AF01.DEF")); //blue
flags4.push_back(CDefHandler::giveDef("AF02.DEF")); //tan
flags4.push_back(CDefHandler::giveDef("AF03.DEF")); //green
flags4.push_back(CDefHandler::giveDef("AF04.DEF")); //orange
flags4.push_back(CDefHandler::giveDef("AF05.DEF")); //purple
flags4.push_back(CDefHandler::giveDef("AF06.DEF")); //teal
flags4.push_back(CDefHandler::giveDef("AF07.DEF")); //pink
for(int q=0; q<8; ++q)
{
for(int o=0; o<flags4[q]->ourImages.size(); ++o)
{
if(flags4[q]->ourImages[o].groupNumber==6)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.imName = std::string();
flags4[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags4[q]->ourImages[o].groupNumber==7)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.groupNumber = 11;
nci.imName = std::string();
flags4[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags4[q]->ourImages[o].groupNumber==8)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.groupNumber = 12;
nci.imName = std::string();
flags4[q]->ourImages.push_back(nci);
}
o+=8;
}
}
for(int o=0; o<flags4[q]->ourImages.size(); ++o)
{
if(flags4[q]->ourImages[o].groupNumber==1)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.groupNumber = 13;
nci.imName = std::string();
flags4[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags4[q]->ourImages[o].groupNumber==2)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.groupNumber = 14;
nci.imName = std::string();
flags4[q]->ourImages.push_back(nci);
}
o+=8;
}
if(flags4[q]->ourImages[o].groupNumber==3)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
nci.groupNumber = 10;
nci.groupNumber = 15;
nci.imName = std::string();
flags4[q]->ourImages.push_back(nci);
}
o+=8;
}
}
for(int ff=0; ff<flags4[q]->ourImages.size(); ++ff)
{
SDL_SetColorKey(flags4[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
SDL_MapRGB(flags4[q]->ourImages[ff].bitmap->format, 0, 255, 255)
);
}
flags4[q]->alphaTransformed = true;
}
}
void CHeroHandler::loadHeroes()
{
int ID=0;
std::string buf = CGI->bitmaph->getTextFile("HOTRAITS.TXT");
std::string buf = bitmaph->getTextFile("HOTRAITS.TXT");
int it=0;
std::string dump;
for(int i=0; i<2; ++i)
{
CGeneralTextHandler::loadToIt(dump,buf,it,3);
loadToIt(dump,buf,it,3);
}
int numberOfCurrentClassHeroes = 0;
@ -395,15 +68,15 @@ void CHeroHandler::loadHeroes()
}
std::string pom ;
CGeneralTextHandler::loadToIt(nher->name,buf,it,4);
loadToIt(nher->name,buf,it,4);
for(int x=0;x<3;x++)
{
CGeneralTextHandler::loadToIt(pom,buf,it,4);
loadToIt(pom,buf,it,4);
nher->lowStack[x] = atoi(pom.c_str());
CGeneralTextHandler::loadToIt(pom,buf,it,4);
loadToIt(pom,buf,it,4);
nher->highStack[x] = atoi(pom.c_str());
CGeneralTextHandler::loadToIt(nher->refTypeStack[x],buf,it,(x==2) ? (3) : (4));
loadToIt(nher->refTypeStack[x],buf,it,(x==2) ? (3) : (4));
int hlp = nher->refTypeStack[x].find_first_of(' ',0);
if(hlp>=0)
nher->refTypeStack[x].replace(hlp,1,"");
@ -436,34 +109,34 @@ void CHeroHandler::loadHeroes()
}
void CHeroHandler::loadSpecialAbilities()
{
std::string buf = CGI->bitmaph->getTextFile("HEROSPEC.TXT");
std::string buf = bitmaph->getTextFile("HEROSPEC.TXT");
int it=0;
std::string dump;
for(int i=0; i<2; ++i)
{
CGeneralTextHandler::loadToIt(dump,buf,it,3);
loadToIt(dump,buf,it,3);
}
for (int i=0;i<heroes.size();i++)
{
CGeneralTextHandler::loadToIt(heroes[i]->bonusName,buf,it,4);
CGeneralTextHandler::loadToIt(heroes[i]->shortBonus,buf,it,4);
CGeneralTextHandler::loadToIt(heroes[i]->longBonus,buf,it,3);
loadToIt(heroes[i]->bonusName,buf,it,4);
loadToIt(heroes[i]->shortBonus,buf,it,4);
loadToIt(heroes[i]->longBonus,buf,it,3);
}
}
void CHeroHandler::loadBiographies()
{
std::string buf = CGI->bitmaph->getTextFile("HEROBIOS.TXT");
std::string buf = bitmaph->getTextFile("HEROBIOS.TXT");
int it=0;
for (int i=0;i<heroes.size();i++)
{
CGeneralTextHandler::loadToIt(heroes[i]->biography,buf,it,3);
loadToIt(heroes[i]->biography,buf,it,3);
}
}
void CHeroHandler::loadHeroClasses()
{
std::string buf = CGI->bitmaph->getTextFile("HCTRAITS.TXT");
std::string buf = bitmaph->getTextFile("HCTRAITS.TXT");
int andame = buf.size();
for(int y=0; y<andame; ++y)
if(buf[y]==',')
@ -561,7 +234,7 @@ void CHeroHandler::loadHeroClasses()
//CHero kkk = heroes[0];
for(int dd=0; dd<CGI->abilh->abilities.size(); ++dd)
for(int dd=0; dd<SKILL_QUANTITY; ++dd)
{
befi=i;
for(i; i<andame; ++i)

View File

@ -1,13 +1,8 @@
#ifndef CHEROHANDLER_H
#define CHEROHANDLER_H
#include "../global.h"
#include <string>
#include <vector>
#include "CCreatureHandler.h"
#include "SDL.h"
#include "../int3.h"
#include "CAmbarCendamo.h"
#include "../CGameInterface.h"
class CHeroClass;
class CDefHandler;
@ -26,8 +21,6 @@ public:
CHeroClass * heroClass;
EHeroClasses heroType; //hero class
//bool operator<(CHero& drugi){if (ID < drugi.ID) return true; else return false;}
SDL_Surface * portraitSmall; //48x32 px
SDL_Surface * portraitLarge; //58x64 px
};
class CHeroClass
@ -48,9 +41,6 @@ class CHeroHandler
public:
std::vector<CHero*> heroes; //by³o nodrze
std::vector<CHeroClass *> heroClasses;
std::vector<CDefHandler *> flags1, flags2, flags3, flags4; //flags blitted on heroes when ,
CDefHandler * pskillsb, *resources; //82x93
CDefHandler * un44; //many things
std::vector<std::string> pskillsn;
std::vector<int> expPerLevel; //expPerLEvel[i] is amount of exp needed to reach level i; if it is not in this vector, multiplicate last value by 1,2 to get next value
unsigned int level(unsigned int experience);
@ -59,18 +49,9 @@ public:
void loadSpecialAbilities();
void loadBiographies();
void loadHeroClasses();
void loadPortraits(); //loads also imgs and names of primary skills
void loadHeroFlags();
void loadPortraits(); //loads names of primary skills
void initHeroClasses();
~CHeroHandler();
void initTerrainCosts();
friend void CAmbarCendamo::deh3m();
friend void initGameState(CGameInfo * cgi);
//friend class CConsoleHandler;
//friend void CPlayerInterface::heroMoved(const HeroMoveDetails & details); //TODO: wywalic, wstretne!!!
};
#endif //CHEROHANDLER_H

View File

@ -1,16 +1,15 @@
#include "../stdafx.h"
#include "CObjectHandler.h"
#include "../CGameInfo.h"
#include "CGeneralTextHandler.h"
#include "CLodHandler.h"
#include "CAmbarCendamo.h"
#include "../mapHandler.h"
#include "CDefObjInfoHandler.h"
#include "../CLua.h"
#include "CDefHandler.h"
#include "../CGameInfo.h"
#include "CLodHandler.h"
#include "CDefObjInfoHandler.h"
#include "CHeroHandler.h"
#include <boost/algorithm/string/replace.hpp>
#include "CTownHandler.h"
#include "CArtHandler.h"
DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
void CObjectHandler::loadObjects()
{
int ID=0;
@ -19,7 +18,7 @@ void CObjectHandler::loadObjects()
while (it<buf.length()-1)
{
CObject nobj;
CGeneralTextHandler::loadToIt(nobj.name,buf,it,3);
loadToIt(nobj.name,buf,it,3);
if(nobj.name.size() && (nobj.name[nobj.name.size()-1]==(char)10 || nobj.name[nobj.name.size()-1]==(char)13 || nobj.name[nobj.name.size()-1]==(char)9))
nobj.name = nobj.name.substr(0, nobj.name.size()-1);
objects.push_back(nobj);
@ -30,7 +29,7 @@ void CObjectHandler::loadObjects()
std::string temp;
while (it<buf.length()-1)
{
CGeneralTextHandler::loadToIt(temp,buf,it,3);
loadToIt(temp,buf,it,3);
if (temp[0]=='\"')
temp = temp.substr(1,temp.length()-2);
boost::algorithm::replace_all(temp,"\"\"","\"");
@ -41,7 +40,7 @@ void CObjectHandler::loadObjects()
it=0;
while (it<buf.length()-1)
{
CGeneralTextHandler::loadToIt(temp,buf,it,3);
loadToIt(temp,buf,it,3);
xtrainfo.push_back(temp);
}
@ -49,7 +48,7 @@ void CObjectHandler::loadObjects()
it=0;
while (it<buf.length()-1)
{
CGeneralTextHandler::loadToIt(temp,buf,it,3);
loadToIt(temp,buf,it,3);
mines.push_back(std::pair<std::string,std::string>(temp,""));
}
@ -58,7 +57,7 @@ void CObjectHandler::loadObjects()
int i=0;
while (it<buf.length()-1)
{
CGeneralTextHandler::loadToIt(temp,buf,it,3);
loadToIt(temp,buf,it,3);
temp = temp.substr(1,temp.length()-2);
mines[i++].second = temp;
}
@ -67,7 +66,7 @@ void CObjectHandler::loadObjects()
it=0;
while (it<buf.length()-1)
{
CGeneralTextHandler::loadToIt(temp,buf,it,3);
loadToIt(temp,buf,it,3);
restypes.push_back(temp);
}
@ -87,7 +86,7 @@ void CObjectHandler::loadObjects()
it=0;
while (it<buf.length()-1)
{
CGeneralTextHandler::loadToIt(temp,buf,it,3);
loadToIt(temp,buf,it,3);
creGens.push_back(temp);
}
@ -146,10 +145,6 @@ bool CGObjectInstance::operator<(const CGObjectInstance & cmp) const //screen p
return true;
if(!cmp.defInfo->isVisitable() && defInfo->isVisitable())
return false;
//if(defInfo->isOnDefList && !(cmp.defInfo->isOnDefList))
// return true;
//if(cmp.defInfo->isOnDefList && !(defInfo->isOnDefList))
// return false;
if(this->pos.x<cmp.pos.x)
return true;
return false;
@ -165,13 +160,13 @@ unsigned int CGHeroInstance::getTileCost(const EterrainType & ttype, const Eroad
unsigned int ret = type->heroClass->terrCosts[ttype];
switch(rdtype)
{
case Eroad::dirtRoad:
case dirtRoad:
ret*=0.75;
break;
case Eroad::grazvelRoad:
case grazvelRoad:
ret*=0.667;
break;
case Eroad::cobblestoneRoad:
case cobblestoneRoad:
ret*=0.5;
break;
}

View File

@ -1,24 +1,19 @@
#define VCMI_DLL
#include "../stdafx.h"
#include "CTownHandler.h"
#include "../CGameInfo.h"
#include "CLodHandler.h"
#include <sstream>
#include "CGeneralTextHandler.h"
extern CLodHandler * bitmaph;
void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
CTownHandler::CTownHandler()
{
smallIcons = CDefHandler::giveDef("ITPA.DEF");
resources = CDefHandler::giveDef("RESOURCE.DEF");
}
{}
CTownHandler::~CTownHandler()
{
delete smallIcons;
//todo - delete structures info
}
{}
void CTownHandler::loadNames()
{
std::istringstream ins, names;
ins.str(CGI->bitmaph->getTextFile("TOWNTYPE.TXT"));
names.str(CGI->bitmaph->getTextFile("TOWNNAME.TXT"));
ins.str(bitmaph->getTextFile("TOWNTYPE.TXT"));
names.str(bitmaph->getTextFile("TOWNNAME.TXT"));
int si=0;
char bufname[75];
while (!ins.eof())
@ -40,21 +35,21 @@ void CTownHandler::loadNames()
towns.push_back(town);
}
std::string strs = CGI->bitmaph->getTextFile("TCOMMAND.TXT");
std::string strs = bitmaph->getTextFile("TCOMMAND.TXT");
int itr=0;
while(itr<strs.length()-1)
{
std::string tmp;
CGeneralTextHandler::loadToIt(tmp, strs, itr, 3);
loadToIt(tmp, strs, itr, 3);
tcommands.push_back(tmp);
}
strs = CGI->bitmaph->getTextFile("HALLINFO.TXT");
strs = bitmaph->getTextFile("HALLINFO.TXT");
itr=0;
while(itr<strs.length()-1)
{
std::string tmp;
CGeneralTextHandler::loadToIt(tmp, strs, itr, 3);
loadToIt(tmp, strs, itr, 3);
hcommands.push_back(tmp);
}
@ -276,32 +271,4 @@ void CTownHandler::loadNames()
of.close();
of.clear();
}
}
SDL_Surface * CTownHandler::getPic(int ID, bool fort, bool builded)
{
if (ID==-1)
return smallIcons->ourImages[0].bitmap;
else if (ID==-2)
return smallIcons->ourImages[1].bitmap;
else if (ID==-3)
return smallIcons->ourImages[2+F_NUMBER*4].bitmap;
else if (ID>F_NUMBER || ID<-3)
throw new std::exception("Invalid ID");
else
{
int pom = 3;
if(!fort)
pom+=F_NUMBER*2;
pom += ID*2;
if (!builded)
pom--;
return smallIcons->ourImages[pom].bitmap;
}
}
int CTownHandler::getTypeByDefName(std::string name)
{
//TODO
return 0;
}
}

View File

@ -1,12 +1,6 @@
#ifndef CTOWNHANDLER_H
#define CTOWNHANDLER_H
#include "CDefHandler.h"
#include "CCreatureHandler.h"
#include "SDL.h"
#include "../int3.h"
#include <string>
#include <vector>
#include "../global.h"
#include <set>
class CBuilding;
class CSpell;
@ -24,7 +18,7 @@ public:
int typeID;
};
struct Structure
struct DLL_EXPORT Structure
{
int ID;
int3 pos;
@ -39,20 +33,17 @@ struct Structure
}
};
class CTownHandler
class DLL_EXPORT CTownHandler
{
public:
CDefHandler * smallIcons, *resources; //resources 32x32
CTownHandler();
~CTownHandler();
std::vector<CTown> towns;
std::vector<std::string> tcommands, hcommands;
void loadNames();
SDL_Surface * getPic(int ID, bool fort=true, bool builded=false); //ID=-1 - blank; -2 - border; -3 - random
static int getTypeByDefName(std::string name);
std::map<int,std::map<int, Structure*> > structures; // <town ID, <structure ID, structure>>
std::map<int, std::map<int,std::set<int> > > requirements; //requirements[town_id][structure_id] -> set of required buildings
CTownHandler();
~CTownHandler();
void loadNames();
};
#endif //CTOWNHANDLER_H

View File

@ -12,6 +12,7 @@
#include "hch\CHeroHandler.h"
#include "hch\CTownHandler.h"
#include "hch\CArtHandler.h"
#include "client\Graphics.h"
#include <iomanip>
#include <sstream>
extern SDL_Surface * screen;
@ -899,7 +900,7 @@ void CMapHandler::init()
//if(h<0)
h=pickHero(i);
CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,h,hpos,i);
nnn->defInfo->handler = CGI->heroh->flags1[0];
nnn->defInfo->handler = graphics->flags1[0];
map->heroes.push_back(nnn);
map->objects.push_back(nnn);
}
@ -1045,7 +1046,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;
SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr);
SDL_BlitSurface(graphics->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)
{
@ -1074,7 +1075,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
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);
SDL_BlitSurface(graphics->flags4[themp->getOwner()]->ourImages[ getHeroFrameNum(themp->moveDir, !themp->isStanding) *8+(heroAnim/4)%imgVal].bitmap, NULL, su, &bufr);
themp->flagPrinted = true;
}
}

View File

@ -10,6 +10,7 @@
#include <tchar.h>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include "global.h"