1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

Rest of commit: broken battles, starting hero, town displaying and linker errors.

Further changes for netcode.
This commit is contained in:
Michał W. Urbańczyk
2008-06-30 00:06:41 +00:00
parent b26024e607
commit ea8562a6b1
33 changed files with 1027 additions and 2450 deletions

View File

@ -7,6 +7,7 @@
#include "hch/CTownHandler.h" #include "hch/CTownHandler.h"
#include "CLua.h" #include "CLua.h"
#include "CCallback.h" #include "CCallback.h"
#include "client/Graphics.h"
AdventureMapButton::AdventureMapButton () AdventureMapButton::AdventureMapButton ()
{ {
type=2; type=2;
@ -38,7 +39,7 @@ AdventureMapButton::AdventureMapButton
imgs.resize(1); imgs.resize(1);
imgs[0].push_back(temp->ourImages[i].bitmap); imgs[0].push_back(temp->ourImages[i].bitmap);
if(playerColoredButton) if(playerColoredButton)
CSDL_Ext::blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID); graphics->blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
} }
delete temp; delete temp;
if (add) if (add)
@ -52,7 +53,7 @@ AdventureMapButton::AdventureMapButton
{ {
imgs[i+1].push_back(temp->ourImages[j].bitmap); imgs[i+1].push_back(temp->ourImages[j].bitmap);
if(playerColoredButton) if(playerColoredButton)
CSDL_Ext::blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID); graphics->blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
} }
delete temp; delete temp;
} }

View File

@ -113,7 +113,7 @@ void CMinimap::draw()
{ {
for (int jj=0; jj<ho; jj++) for (int jj=0; jj<ho; jj++)
{ {
SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,CGI->playerColors[hh[i]->getOwner()].r,CGI->playerColors[hh[i]->getOwner()].g,CGI->playerColors[hh[i]->getOwner()].b); SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,graphics->playerColors[hh[i]->getOwner()].r,graphics->playerColors[hh[i]->getOwner()].g,graphics->playerColors[hh[i]->getOwner()].b);
} }
} }
} }
@ -600,7 +600,7 @@ CResDataBar::CResDataBar()
//SDL_Color p1={40,65,139,255}, p2={36,59,125,255}, p3={35,56,121,255}; //SDL_Color p1={40,65,139,255}, p2={36,59,125,255}, p3={35,56,121,255};
//kolory+=p1,p2,p3; //kolory+=p1,p2,p3;
//blueToPlayersAdv(bg,LOCPLINT->playerID,2,&kolory); //blueToPlayersAdv(bg,LOCPLINT->playerID,2,&kolory);
blueToPlayersAdv(bg,LOCPLINT->playerID,2); graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
pos = genRect(bg->h,bg->w,3,575); pos = genRect(bg->h,bg->w,3,575);
txtpos += (std::pair<int,int>(35,577)),(std::pair<int,int>(120,577)),(std::pair<int,int>(205,577)), txtpos += (std::pair<int,int>(35,577)),(std::pair<int,int>(120,577)),(std::pair<int,int>(205,577)),
@ -851,7 +851,7 @@ townList(5,&genRect(192,48,747,196),747,196,747,372)
townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this); townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
LOCPLINT->adventureInt=this; LOCPLINT->adventureInt=this;
bg = BitmapHandler::loadBitmap("ADVMAP.bmp"); bg = BitmapHandler::loadBitmap("ADVMAP.bmp");
blueToPlayersAdv(bg,player); graphics->blueToPlayersAdv(bg,player);
scrollingLeft = false; scrollingLeft = false;
scrollingRight = false; scrollingRight = false;
scrollingUp = false ; scrollingUp = false ;

View File

@ -10,6 +10,7 @@
#include "CGameState.h" #include "CGameState.h"
#include "hch\CGeneralTextHandler.h" #include "hch\CGeneralTextHandler.h"
#include "client/CCreatureAnimation.h" #include "client/CCreatureAnimation.h"
#include "client/Graphics.h"
#include <queue> #include <queue>
#include <sstream> #include <sstream>
@ -37,7 +38,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
std::vector< std::string > & backref = CGI->mh->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ]; std::vector< std::string > & backref = CGI->mh->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ];
background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] ); background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] );
menu = BitmapHandler::loadBitmap("CBAR.BMP"); menu = BitmapHandler::loadBitmap("CBAR.BMP");
CSDL_Ext::blueToPlayersAdv(menu, hero1->tempOwner); graphics->blueToPlayersAdv(menu, hero1->tempOwner);
//preparing graphics for displaying amounts of creatures //preparing graphics for displaying amounts of creatures
amountBasic = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); amountBasic = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
@ -949,7 +950,7 @@ CBattleHero::CBattleHero(std::string defName, int phaseG, int imageG, bool flipG
for(int i=0; i<flag->ourImages.size(); ++i) for(int i=0; i<flag->ourImages.size(); ++i)
{ {
flag->ourImages[i].bitmap = CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap); flag->ourImages[i].bitmap = CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap);
CSDL_Ext::blueToPlayersAdv(flag->ourImages[i].bitmap, player); graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player);
} }
} }

View File

@ -364,6 +364,11 @@ UpgradeInfo CCallback::getUpgradeInfo(const CArmedInstance *obj, int stackPos)
return ret; return ret;
} }
const StartInfo * CCallback::getStartInfo()
{
return gs->scenarioOps;
}
int CCallback::howManyTowns() int CCallback::howManyTowns()
{ {
return gs->players[gs->currentPlayer].towns.size(); return gs->players[gs->currentPlayer].towns.size();
@ -484,7 +489,7 @@ std::vector < std::string > CCallback::getObjDescriptions(int3 pos)
else return std::vector< std::string > (); else return std::vector< std::string > ();
} }
PseudoV< PseudoV< PseudoV<unsigned char> > > & CCallback::getVisibilityMap() std::vector< std::vector< std::vector<unsigned char> > > & CCallback::getVisibilityMap()
{ {
return gs->players[player].fogOfWarMap; return gs->players[player].fogOfWarMap;
} }
@ -844,7 +849,7 @@ int3 CScriptCallback::getPos(CGObjectInstance * ob)
} }
void CScriptCallback::changePrimSkill(int ID, int which, int val) void CScriptCallback::changePrimSkill(int ID, int which, int val)
{ {
CGHeroInstance * hero = CGI->state->getHero(ID,0); CGHeroInstance * hero = CGI->state->map->getHero(ID,0);
if (which<PRIMARY_SKILLS) if (which<PRIMARY_SKILLS)
{ {
hero->primSkills[which]+=val; hero->primSkills[which]+=val;
@ -884,7 +889,7 @@ void CScriptCallback::changePrimSkill(int ID, int which, int val)
int CScriptCallback::getHeroOwner(int heroID) int CScriptCallback::getHeroOwner(int heroID)
{ {
CGHeroInstance * hero = CGI->state->getHero(heroID,0); CGHeroInstance * hero = CGI->state->map->getHero(heroID,0);
return hero->getOwner(); return hero->getOwner();
} }
void CScriptCallback::showInfoDialog(int player, std::string text, std::vector<SComponent*> * components) void CScriptCallback::showInfoDialog(int player, std::string text, std::vector<SComponent*> * components)
@ -966,13 +971,13 @@ void CScriptCallback::heroVisitCastle(CGObjectInstance * ob, int heroID)
CGTownInstance * n; CGTownInstance * n;
if(n = dynamic_cast<CGTownInstance*>(ob)) if(n = dynamic_cast<CGTownInstance*>(ob))
{ {
n->visitingHero = CGI->state->getHero(heroID,0); n->visitingHero = CGI->state->map->getHero(heroID,0);
CGI->state->getHero(heroID,0)->visitedTown = n; CGI->state->map->getHero(heroID,0)->visitedTown = n;
for(int b=0; b<CGI->playerint.size(); ++b) for(int b=0; b<CGI->playerint.size(); ++b)
{ {
if(CGI->playerint[b]->playerID == getHeroOwner(heroID)) if(CGI->playerint[b]->playerID == getHeroOwner(heroID))
{ {
CGI->playerint[b]->heroVisitsTown(CGI->state->getHero(heroID,0),n); CGI->playerint[b]->heroVisitsTown(CGI->state->map->getHero(heroID,0),n);
break; break;
} }
} }
@ -986,7 +991,7 @@ void CScriptCallback::stopHeroVisitCastle(CGObjectInstance * ob, int heroID)
CGTownInstance * n; CGTownInstance * n;
if(n = dynamic_cast<CGTownInstance*>(ob)) if(n = dynamic_cast<CGTownInstance*>(ob))
{ {
CGI->state->getHero(heroID,0)->visitedTown = NULL; CGI->state->map->getHero(heroID,0)->visitedTown = NULL;
if(n->visitingHero && n->visitingHero->type->ID == heroID) if(n->visitingHero && n->visitingHero->type->ID == heroID)
n->visitingHero = NULL; n->visitingHero = NULL;
return; return;
@ -996,7 +1001,7 @@ void CScriptCallback::stopHeroVisitCastle(CGObjectInstance * ob, int heroID)
} }
void CScriptCallback::giveHeroArtifact(int artid, int hid, int position) //pos==-1 - first free slot in backpack void CScriptCallback::giveHeroArtifact(int artid, int hid, int position) //pos==-1 - first free slot in backpack
{ {
CGHeroInstance* h = gs->getHero(hid,0); CGHeroInstance* h = gs->map->getHero(hid,0);
if(position<0) if(position<0)
{ {
for(int i=0;i<h->artifacts.size();i++) for(int i=0;i<h->artifacts.size();i++)
@ -1026,7 +1031,7 @@ void CScriptCallback::startBattle(CCreatureSet * army1, CCreatureSet * army2, in
} }
void CScriptCallback::startBattle(int heroID, CCreatureSet * army, int3 tile) //for hero<=>neutral army void CScriptCallback::startBattle(int heroID, CCreatureSet * army, int3 tile) //for hero<=>neutral army
{ {
CGHeroInstance* h = gs->getHero(heroID,0); CGHeroInstance* h = gs->map->getHero(heroID,0);
gs->battle(&h->army,army,tile,h,NULL); gs->battle(&h->army,army,tile,h,NULL);
} }
void CLuaCallback::registerFuncs(lua_State * L) void CLuaCallback::registerFuncs(lua_State * L)

View File

@ -40,7 +40,7 @@ public:
//get info //get info
virtual bool verifyPath(CPath * path, bool blockSea)=0; virtual bool verifyPath(CPath * path, bool blockSea)=0;
virtual int getDate(int mode=0)=0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month virtual int getDate(int mode=0)=0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
virtual PseudoV< PseudoV< PseudoV<unsigned char> > > & getVisibilityMap()=0; //returns visibility map (TODO: make it const) virtual std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap()=0; //returns visibility map (TODO: make it const)
virtual const CGHeroInstance * getHeroInfo(int player, int val, bool mode)=0; //mode = 0 -> val = serial; mode = 1 -> val = ID virtual const CGHeroInstance * getHeroInfo(int player, int val, bool mode)=0; //mode = 0 -> val = serial; mode = 1 -> val = ID
virtual int getResourceAmount(int type)=0; virtual int getResourceAmount(int type)=0;
virtual int howManyHeroes()=0; virtual int howManyHeroes()=0;
@ -54,6 +54,7 @@ public:
virtual int getHeroSerial(const CGHeroInstance * hero)=0; virtual int getHeroSerial(const CGHeroInstance * hero)=0;
virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)=0; virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)=0;
virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)=0; virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)=0;
virtual const StartInfo * getStartInfo()=0;
//battle //battle
virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
@ -110,7 +111,7 @@ public:
//get info //get info
bool verifyPath(CPath * path, bool blockSea); bool verifyPath(CPath * path, bool blockSea);
int getDate(int mode=0); //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month int getDate(int mode=0); //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
PseudoV< PseudoV< PseudoV<unsigned char> > > & getVisibilityMap(); //returns visibility map (TODO: make it const) std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap(); //returns visibility map (TODO: make it const)
const CGHeroInstance * getHeroInfo(int player, int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID const CGHeroInstance * getHeroInfo(int player, int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
int getResourceAmount(int type); int getResourceAmount(int type);
std::vector<int> getResourceAmount(); std::vector<int> getResourceAmount();
@ -126,6 +127,7 @@ public:
int getMySerial(); int getMySerial();
const CCreatureSet* getGarrison(const CGObjectInstance *obj); const CCreatureSet* getGarrison(const CGObjectInstance *obj);
UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos); UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos);
virtual const StartInfo * getStartInfo();
//battle //battle
int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
@ -169,7 +171,7 @@ public:
void startBattle(int heroID, CCreatureSet * army, int3 tile); //for hero<=>neutral army void startBattle(int heroID, CCreatureSet * army, int3 tile); //for hero<=>neutral army
//friends //friends
friend void initGameState(Mapa * map, CGameInfo * cgi); friend CGameState;
}; };
class CLuaCallback : public CScriptCallback class CLuaCallback : public CScriptCallback
{ {
@ -181,6 +183,6 @@ private:
static int getGnrlText(lua_State * L);//(int ID, int which, int val); static int getGnrlText(lua_State * L);//(int ID, int which, int val);
static int getSelectedHero(lua_State * L);//() static int getSelectedHero(lua_State * L);//()
friend void initGameState(Mapa * map, CGameInfo * cgi); friend CGameState;
}; };
#endif //CCALLBACK_H #endif //CCALLBACK_H

View File

@ -235,7 +235,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
if((townlist->selected+1) > townlist->SIZE) if((townlist->selected+1) > townlist->SIZE)
townlist->from = townlist->selected - townlist->SIZE + 2; townlist->from = townlist->selected - townlist->SIZE + 2;
CSDL_Ext::blueToPlayersAdv(townInt,LOCPLINT->playerID); graphics->blueToPlayersAdv(townInt,LOCPLINT->playerID);
exit->bitmapOffset = 4; exit->bitmapOffset = 4;
@ -660,7 +660,7 @@ CHallInterface::CResDataBar::CResDataBar()
{ {
bg = BitmapHandler::loadBitmap("Z2ESBAR.bmp"); bg = BitmapHandler::loadBitmap("Z2ESBAR.bmp");
SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
CSDL_Ext::blueToPlayersAdv(bg,LOCPLINT->playerID); graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
pos.x = 7; pos.x = 7;
pos.y = 575; pos.y = 575;
pos.w = bg->w; pos.w = bg->w;
@ -770,7 +770,7 @@ CHallInterface::CBuildingBox::CBuildingBox(int id, int x, int y)
CHallInterface::CHallInterface(CCastleInterface * owner) CHallInterface::CHallInterface(CCastleInterface * owner)
{ {
bg = BitmapHandler::loadBitmap(CGI->buildh->hall[owner->town->subID].first); bg = BitmapHandler::loadBitmap(CGI->buildh->hall[owner->town->subID].first);
CSDL_Ext::blueToPlayersAdv(bg,LOCPLINT->playerID); graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
bars = CDefHandler::giveDefEss("TPTHBAR.DEF"); bars = CDefHandler::giveDefEss("TPTHBAR.DEF");
status = CDefHandler::giveDefEss("TPTHCHK.DEF"); status = CDefHandler::giveDefEss("TPTHCHK.DEF");
exit = new AdventureMapButton exit = new AdventureMapButton
@ -1014,7 +1014,7 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod
SDL_FreeSurface(hhlp); SDL_FreeSurface(hhlp);
pos.x = screen->w/2 - bitmap->w/2; pos.x = screen->w/2 - bitmap->w/2;
pos.y = screen->h/2 - bitmap->h/2; pos.y = screen->h/2 - bitmap->h/2;
CSDL_Ext::blueToPlayersAdv(bitmap,LOCPLINT->playerID); graphics->blueToPlayersAdv(bitmap,LOCPLINT->playerID);
blitAt(LOCPLINT->castleInt->bicons->ourImages[bid].bitmap,125,50,bitmap); blitAt(LOCPLINT->castleInt->bicons->ourImages[bid].bitmap,125,50,bitmap);
std::vector<std::string> pom; pom.push_back(CGI->buildh->buildings[tid][bid]->name); std::vector<std::string> pom; pom.push_back(CGI->buildh->buildings[tid][bid]->name);
CSDL_Ext::printAtMiddleWB(CGI->buildh->buildings[tid][bid]->description,197,168,GEOR16,40,zwykly,bitmap); CSDL_Ext::printAtMiddleWB(CGI->buildh->buildings[tid][bid]->description,197,168,GEOR16,40,zwykly,bitmap);

View File

@ -142,7 +142,7 @@ int internalFunc(void * callback)
// break; // break;
} }
//SDL_Delay(100); //SDL_Delay(100);
delete p; //delete p;
} }
} }
return -1; return -1;

View File

@ -62,9 +62,6 @@ public:
CScreenHandler * screenh; CScreenHandler * screenh;
int localPlayer; int localPlayer;
std::vector<CGameInterface *> playerint; std::vector<CGameInterface *> playerint;
std::vector<SDL_Color> playerColors;
SDL_Color neutralColor;
StartInfo scenarioOps;
}; };
#endif //CGAMEINFO_H #endif //CGAMEINFO_H

View File

@ -1,13 +1,28 @@
#define VCMI_DLL
#include <algorithm>
#include <queue>
#include <fstream>
#include "CGameState.h" #include "CGameState.h"
#include "CGameInterface.h" #include "CGameInterface.h"
#include "CPlayerInterface.h" #include "CPlayerInterface.h"
#include <algorithm>
#include "SDL_Thread.h"
#include "SDL_Extensions.h" #include "SDL_Extensions.h"
#include "CBattleInterface.h" //for CBattleHex #include "CBattleInterface.h" //for CBattleHex
#include <queue> #include <boost/random/linear_congruential.hpp>
#include "hch/CDefObjInfoHandler.h"
#include "hch/CArtHandler.h"
#include "hch/CTownHandler.h"
#include "hch/CHeroHandler.h"
#include "hch/CObjectHandler.h"
#include "hch/CCreatureHandler.h"
#include "lib/VCMI_Lib.h"
#include "map.h"
#include "StartInfo.h"
#include "CLua.h"
#include "CCallback.h"
#include "CLuaHandler.h"
boost::rand48 ran;
class CMP_stack class CMP_stack
{ {
public: public:
@ -17,8 +32,509 @@ public:
} }
} cmpst ; } cmpst ;
void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2) CStack::CStack(CCreature * C, int A, int O, int I, bool AO)
:creature(C),amount(A),owner(O), alive(true), position(-1), ID(I), attackerOwned(AO), firstHPleft(C->hitPoints)
{ {
}
int CGameState::pickHero(int owner)
{
int h=-1;
if(map->getHero(h = scenarioOps->getIthPlayersSettings(owner).hero,0) && h>=0) //we haven't used selected hero
return h;
int f = scenarioOps->getIthPlayersSettings(owner).castle;
int i=0;
do //try to find free hero of our faction
{
i++;
h = scenarioOps->getIthPlayersSettings(owner).castle*HEROES_PER_TYPE*2+(ran()%(HEROES_PER_TYPE*2));//->scenarioOps->playerInfos[pru].hero = VLC->
} while( map->getHero(h) && i<175);
if(i>174) //probably no free heroes - there's no point in further search, we'll take first free
{
std::cout << "Warning: cannot find free hero - trying to get first available..."<<std::endl;
for(int j=0; j<HEROES_PER_TYPE * 2 * F_NUMBER; j++)
if(!map->getHero(j))
h=j;
}
return h;
}
std::pair<int,int> CGameState::pickObject(CGObjectInstance *obj)
{
switch(obj->ID)
{
case 65: //random artifact
return std::pair<int,int>(5,(ran()%136)+7); //tylko sensowny zakres - na poczatku sa katapulty itp, na koncu specjalne i blanki
case 66: //random treasure artifact
return std::pair<int,int>(5,VLC->arth->treasures[ran()%VLC->arth->treasures.size()]->id);
case 67: //random minor artifact
return std::pair<int,int>(5,VLC->arth->minors[ran()%VLC->arth->minors.size()]->id);
case 68: //random major artifact
return std::pair<int,int>(5,VLC->arth->majors[ran()%VLC->arth->majors.size()]->id);
case 69: //random relic artifact
return std::pair<int,int>(5,VLC->arth->relics[ran()%VLC->arth->relics.size()]->id);
case 70: //random hero
{
return std::pair<int,int>(34,pickHero(obj->tempOwner));
}
case 71: //random monster
return std::pair<int,int>(54,ran()%(VLC->creh->creatures.size()));
case 72: //random monster lvl1
return std::pair<int,int>(54,VLC->creh->levelCreatures[1][ran()%VLC->creh->levelCreatures[1].size()]->idNumber);
case 73: //random monster lvl2
return std::pair<int,int>(54,VLC->creh->levelCreatures[2][ran()%VLC->creh->levelCreatures[2].size()]->idNumber);
case 74: //random monster lvl3
return std::pair<int,int>(54,VLC->creh->levelCreatures[3][ran()%VLC->creh->levelCreatures[3].size()]->idNumber);
case 75: //random monster lvl4
return std::pair<int,int>(54,VLC->creh->levelCreatures[4][ran()%VLC->creh->levelCreatures[4].size()]->idNumber);
case 76: //random resource
return std::pair<int,int>(79,ran()%7); //now it's OH3 style, use %8 for mithril
case 77: //random town
{
int align = ((CGTownInstance*)obj)->alignment,
f;
if(align>PLAYER_LIMIT-1)//same as owner / random
{
if(obj->tempOwner > PLAYER_LIMIT-1)
f = -1; //random
else
f = scenarioOps->getIthPlayersSettings(obj->tempOwner).castle;
}
else
{
f = scenarioOps->getIthPlayersSettings(align).castle;
}
if(f<0) f = ran()%VLC->townh->towns.size();
return std::pair<int,int>(98,f);
}
case 162: //random monster lvl5
return std::pair<int,int>(54,VLC->creh->levelCreatures[5][ran()%VLC->creh->levelCreatures[5].size()]->idNumber);
case 163: //random monster lvl6
return std::pair<int,int>(54,VLC->creh->levelCreatures[6][ran()%VLC->creh->levelCreatures[6].size()]->idNumber);
case 164: //random monster lvl7
return std::pair<int,int>(54,VLC->creh->levelCreatures[7][ran()%VLC->creh->levelCreatures[7].size()]->idNumber);
case 216: //random dwelling
{
int faction = ran()%F_NUMBER;
CCreGen2ObjInfo* info =(CCreGen2ObjInfo*)obj->info;
if (info->asCastle)
{
for(int i=0;i<map->objects.size();i++)
{
if(map->objects[i]->ID==77 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
randomizeObject(map->objects[i]); //we have to randomize the castle first
faction = map->objects[i]->subID;
break;
}
else if(map->objects[i]->ID==98 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
faction = map->objects[i]->subID;
break;
}
}
}
else
{
while((!(info->castles[0]&(1<<faction))))
{
if((faction>7) && (info->castles[1]&(1<<(faction-8))))
break;
faction = ran()%F_NUMBER;
}
}
int level = ((info->maxLevel-info->minLevel) ? (ran()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel));
int cid = VLC->townh->towns[faction].basicCreatures[level];
for(int i=0;i<VLC->objh->cregens.size();i++)
if(VLC->objh->cregens[i]==cid)
return std::pair<int,int>(17,i);
std::cout << "Cannot find a dwelling for creature "<<cid <<std::endl;
return std::pair<int,int>(17,0);
}
case 217:
{
int faction = ran()%F_NUMBER;
CCreGenObjInfo* info =(CCreGenObjInfo*)obj->info;
if (info->asCastle)
{
for(int i=0;i<map->objects.size();i++)
{
if(map->objects[i]->ID==77 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
randomizeObject(map->objects[i]); //we have to randomize the castle first
faction = map->objects[i]->subID;
break;
}
else if(map->objects[i]->ID==98 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
faction = map->objects[i]->subID;
break;
}
}
}
else
{
while((!(info->castles[0]&(1<<faction))))
{
if((faction>7) && (info->castles[1]&(1<<(faction-8))))
break;
faction = ran()%F_NUMBER;
}
}
int cid = VLC->townh->towns[faction].basicCreatures[obj->subID];
for(int i=0;i<VLC->objh->cregens.size();i++)
if(VLC->objh->cregens[i]==cid)
return std::pair<int,int>(17,i);
std::cout << "Cannot find a dwelling for creature "<<cid <<std::endl;
return std::pair<int,int>(17,0);
}
case 218:
{
CCreGen3ObjInfo* info =(CCreGen3ObjInfo*)obj->info;
int level = ((info->maxLevel-info->minLevel) ? (ran()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel));
int cid = VLC->townh->towns[obj->subID].basicCreatures[level];
for(int i=0;i<VLC->objh->cregens.size();i++)
if(VLC->objh->cregens[i]==cid)
return std::pair<int,int>(17,i);
std::cout << "Cannot find a dwelling for creature "<<cid <<std::endl;
return std::pair<int,int>(17,0);
}
}
return std::pair<int,int>(-1,-1);
}
void CGameState::randomizeObject(CGObjectInstance *cur)
{
std::pair<int,int> ran = pickObject(cur);
if(ran.first<0 || ran.second<0) //this is not a random object, or we couldn't find anything
{
if(cur->ID==98) //town - set def
{
CGTownInstance *t = dynamic_cast<CGTownInstance*>(cur);
if(t->hasCapitol())
t->defInfo = capitols[t->subID];
else if(t->hasFort())
t->defInfo = forts[t->subID];
else
t->defInfo = villages[t->subID];
}
return;
}
else if(ran.first==34)//special code for hero
{
CGHeroInstance *h = dynamic_cast<CGHeroInstance *>(cur);
if(!h) {std::cout<<"Wrong random hero at "<<cur->pos<<std::endl; return;}
cur->ID = ran.first;
cur->subID = ran.second;
h->type = VLC->heroh->heroes[ran.second];
map->heroes.push_back(h);
return; //TODO: maybe we should do something with definfo?
}
else if(ran.first==98)//special code for town
{
CGTownInstance *t = dynamic_cast<CGTownInstance*>(cur);
if(!t) {std::cout<<"Wrong random town at "<<cur->pos<<std::endl; return;}
cur->ID = ran.first;
cur->subID = ran.second;
t->town = &VLC->townh->towns[ran.second];
if(t->hasCapitol())
t->defInfo = capitols[t->subID];
else if(t->hasFort())
t->defInfo = forts[t->subID];
else
t->defInfo = villages[t->subID];
map->towns.push_back(t);
return;
}
//we have to replace normal random object
cur->ID = ran.first;
cur->subID = ran.second;
map->defs.insert(cur->defInfo = VLC->dobjinfo->gobjs[ran.first][ran.second]);
if(!cur->defInfo){std::cout<<"Missing def declaration for "<<cur->ID<<" "<<cur->subID<<std::endl;return;}
}
void CGameState::init(StartInfo * si, Mapa * map, int seed)
{
ran.seed((long)seed);
scenarioOps = si;
this->map = map;
for(int i=0;i<F_NUMBER;i++)
{
villages[i] = new CGDefInfo(*VLC->dobjinfo->castles[i]);
forts[i] = VLC->dobjinfo->castles[i];
capitols[i] = new CGDefInfo(*VLC->dobjinfo->castles[i]);
}
//picking random factions for players
for(int i=0;i<scenarioOps->playerInfos.size();i++)
{
if(scenarioOps->playerInfos[i].castle==-1)
{
int f;
do
{
f = ran()%F_NUMBER;
}while(!(map->players[scenarioOps->playerInfos[i].color].allowedFactions & 1<<f));
scenarioOps->playerInfos[i].castle = f;
}
}
//randomizing objects
for(int no=0; no<map->objects.size(); ++no)
{
randomizeObject(map->objects[no]);
if(map->objects[no]->ID==26)
map->objects[no]->defInfo->handler=NULL;
}
//std::cout<<"\tRandomizing objects: "<<th.getDif()<<std::endl;
day=0;
/*********creating players entries in gs****************************************/
for (int i=0; i<scenarioOps->playerInfos.size();i++)
{
std::pair<int,PlayerState> ins(scenarioOps->playerInfos[i].color,PlayerState());
ins.second.color=ins.first;
ins.second.serial=i;
players.insert(ins);
}
/******************RESOURCES****************************************************/
//TODO: zeby komputer dostawal inaczej niz gracz
std::vector<int> startres;
std::ifstream tis("config/startres.txt");
int k;
for (int j=0;j<scenarioOps->difficulty;j++)
{
tis >> k;
for (int z=0;z<RESOURCE_QUANTITY;z++)
tis>>k;
}
tis >> k;
for (int i=0;i<RESOURCE_QUANTITY;i++)
{
tis >> k;
startres.push_back(k);
}
tis.close();
for (std::map<int,PlayerState>::iterator i = players.begin(); i!=players.end(); i++)
{
(*i).second.resources.resize(RESOURCE_QUANTITY);
for (int x=0;x<RESOURCE_QUANTITY;x++)
(*i).second.resources[x] = startres[x];
}
/*************************HEROES************************************************/
for (int i=0; i<map->heroes.size();i++) //heroes instances
{
if (map->heroes[i]->getOwner()<0)
continue;
CGHeroInstance * vhi = (map->heroes[i]);
if(!vhi->type)
vhi->type = VLC->heroh->heroes[vhi->subID];
//vhi->subID = vhi->type->ID;
if (vhi->level<1)
{
vhi->exp=40+ran()%50;
vhi->level = 1;
}
if (vhi->level>1) ;//TODO dodac um dr, ale potrzebne los
if ((!vhi->primSkills.size()) || (vhi->primSkills[0]<0))
{
if (vhi->primSkills.size()<PRIMARY_SKILLS)
vhi->primSkills.resize(PRIMARY_SKILLS);
vhi->primSkills[0] = vhi->type->heroClass->initialAttack;
vhi->primSkills[1] = vhi->type->heroClass->initialDefence;
vhi->primSkills[2] = vhi->type->heroClass->initialPower;
vhi->primSkills[3] = vhi->type->heroClass->initialKnowledge;
}
vhi->mana = vhi->primSkills[3]*10;
if (!vhi->name.length())
{
vhi->name = vhi->type->name;
}
if (!vhi->biography.length())
{
vhi->biography = vhi->type->biography;
}
if (vhi->portrait < 0)
vhi->portrait = vhi->type->ID;
//initial army
if (!vhi->army.slots.size()) //standard army
{
int pom, pom2=0;
for(int x=0;x<3;x++)
{
pom = (VLC->creh->nameToID[vhi->type->refTypeStack[x]]);
if(pom>=145 && pom<=149) //war machine
{
pom2++;
switch (pom)
{
case 145: //catapult
vhi->artifWorn[16] = 3;
break;
default:
pom-=145;
vhi->artifWorn[13+pom] = 4+pom;
break;
}
continue;
}
vhi->army.slots[x-pom2].first = &(VLC->creh->creatures[pom]);
if((pom = (vhi->type->highStack[x]-vhi->type->lowStack[x])) > 0)
vhi->army.slots[x-pom2].second = (ran()%pom)+vhi->type->lowStack[x];
else
vhi->army.slots[x-pom2].second = +vhi->type->lowStack[x];
}
}
players[vhi->getOwner()].heroes.push_back(vhi);
}
/*************************FOG**OF**WAR******************************************/
for(std::map<int, PlayerState>::iterator k=players.begin(); k!=players.end(); ++k)
{
k->second.fogOfWarMap.resize(map->width);
for(int g=0; g<map->width; ++g)
k->second.fogOfWarMap[g].resize(map->height);
for(int g=-0; g<map->width; ++g)
for(int h=0; h<map->height; ++h)
k->second.fogOfWarMap[g][h].resize(map->twoLevel+1, 0);
for(int g=0; g<map->width; ++g)
for(int h=0; h<map->height; ++h)
for(int v=0; v<map->twoLevel+1; ++v)
k->second.fogOfWarMap[g][h][v] = 0;
for(int xd=0; xd<map->width; ++xd) //revealing part of map around heroes
{
for(int yd=0; yd<map->height; ++yd)
{
for(int ch=0; ch<k->second.heroes.size(); ++ch)
{
int deltaX = (k->second.heroes[ch]->getPosition(false).x-xd)*(k->second.heroes[ch]->getPosition(false).x-xd);
int deltaY = (k->second.heroes[ch]->getPosition(false).y-yd)*(k->second.heroes[ch]->getPosition(false).y-yd);
if(deltaX+deltaY<k->second.heroes[ch]->getSightDistance()*k->second.heroes[ch]->getSightDistance())
k->second.fogOfWarMap[xd][yd][k->second.heroes[ch]->getPosition(false).z] = 1;
}
}
}
}
/****************************TOWNS************************************************/
for (int i=0;i<map->towns.size();i++)
{
CGTownInstance * vti =(map->towns[i]);
if(!vti->town)
vti->town = &VLC->townh->towns[vti->subID];
if (vti->name.length()==0) // if town hasn't name we draw it
vti->name=vti->town->names[ran()%vti->town->names.size()];
if(vti->builtBuildings.find(-50)!=vti->builtBuildings.end()) //give standard set of buildings
{
vti->builtBuildings.erase(-50);
vti->builtBuildings.insert(10);
vti->builtBuildings.insert(5);
vti->builtBuildings.insert(30);
if(ran()%2)
vti->builtBuildings.insert(31);
}
players[vti->getOwner()].towns.push_back(vti);
}
for(std::map<int, PlayerState>::iterator k=players.begin(); k!=players.end(); ++k)
{
if(k->first==-1 || k->first==255)
continue;
for(int xd=0; xd<map->width; ++xd) //revealing part of map around towns
{
for(int yd=0; yd<map->height; ++yd)
{
for(int ch=0; ch<k->second.towns.size(); ++ch)
{
int deltaX = (k->second.towns[ch]->pos.x-xd)*(k->second.towns[ch]->pos.x-xd);
int deltaY = (k->second.towns[ch]->pos.y-yd)*(k->second.towns[ch]->pos.y-yd);
if(deltaX+deltaY<k->second.towns[ch]->getSightDistance()*k->second.towns[ch]->getSightDistance())
k->second.fogOfWarMap[xd][yd][k->second.towns[ch]->pos.z] = 1;
}
}
}
//init visiting heroes
for(int l=0; l<k->second.heroes.size();l++)
{
for(int m=0; m<k->second.towns.size();m++)
{
int3 vistile = k->second.towns[m]->pos; vistile.x--; //tile next to the entrance
if(vistile == k->second.heroes[l]->pos)
{
k->second.towns[m]->visitingHero = k->second.heroes[l];
break;
}
}
}
}
/****************************SCRIPTS************************************************/
std::map<int, std::map<std::string, CObjectScript*> > * skrypty = &objscr; //alias for easier access
/****************************C++ OBJECT SCRIPTS************************************************/
std::map<int,CCPPObjectScript*> scripts;
CScriptCallback * csc = new CScriptCallback();
csc->gs = this;
handleCPPObjS(&scripts,new CVisitableOPH(csc));
handleCPPObjS(&scripts,new CVisitableOPW(csc));
handleCPPObjS(&scripts,new CPickable(csc));
handleCPPObjS(&scripts,new CMines(csc));
handleCPPObjS(&scripts,new CTownScript(csc));
handleCPPObjS(&scripts,new CHeroScript(csc));
handleCPPObjS(&scripts,new CMonsterS(csc));
handleCPPObjS(&scripts,new CCreatureGen(csc));
//created map
/****************************LUA OBJECT SCRIPTS************************************************/
std::vector<std::string> * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files
for (int i=0; i<lf->size(); i++)
{
try
{
std::vector<std::string> * temp = CLuaHandler::functionList((*lf)[i]);
CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]);
CLuaCallback::registerFuncs(objs->is);
//objs
for (int j=0; j<temp->size(); j++)
{
int obid ; //obj ID
int dspos = (*temp)[j].find_first_of('_');
obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str());
std::string fname = (*temp)[j].substr(0,dspos);
if (skrypty->find(obid)==skrypty->end())
skrypty->insert(std::pair<int, std::map<std::string, CObjectScript*> >(obid,std::map<std::string,CObjectScript*>()));
(*skrypty)[obid].insert(std::pair<std::string, CObjectScript*>(fname,objs));
}
delete temp;
}HANDLE_EXCEPTION
}
/****************************INITIALIZING OBJECT SCRIPTS************************************************/
std::string temps("newObject");
for (int i=0; i<map->objects.size(); i++)
{
//c++ scripts
if (scripts.find(map->objects[i]->ID) != scripts.end())
{
map->objects[i]->state = scripts[map->objects[i]->ID];
map->objects[i]->state->newObject(map->objects[i]);
}
else
{
map->objects[i]->state = NULL;
}
// lua scripts
if(checkFunc(map->objects[i]->ID,temps))
(*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]);
}
delete lf;
}
void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2)
{/*
curB = new BattleInfo(); curB = new BattleInfo();
std::vector<CStack*> & stacks = (curB->stacks); std::vector<CStack*> & stacks = (curB->stacks);
@ -150,7 +666,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
std::stable_sort(stacks.begin(),stacks.end(),cmpst); std::stable_sort(stacks.begin(),stacks.end(),cmpst);
//for start inform players about battle //for start inform players about battle
for(std::map<int, PlayerState>::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing for(std::map<int, PlayerState>::iterator j=players.begin(); j!=players.end(); ++j)//->players.size(); ++j) //for testing
{ {
if (j->first > PLAYER_LIMIT) if (j->first > PLAYER_LIMIT)
break; break;
@ -163,13 +679,13 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
side = true; side = true;
else else
continue; //no witnesses continue; //no witnesses
if(CGI->playerint[j->second.serial]->human) if(VLC->playerint[j->second.serial]->human)
{ {
((CPlayerInterface*)( CGI->playerint[j->second.serial] ))->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); ((CPlayerInterface*)( VLC->playerint[j->second.serial] ))->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side);
} }
else else
{ {
//CGI->playerint[j->second.serial]->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); //VLC->playerint[j->second.serial]->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side);
} }
} }
} }
@ -188,8 +704,8 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
{ {
bool battleEnd = false; bool battleEnd = false;
//tell players about next round //tell players about next round
for(int v=0; v<CGI->playerint.size(); ++v) for(int v=0; v<VLC->playerint.size(); ++v)
CGI->playerint[v]->battleNewRound(curB->round); VLC->playerint[v]->battleNewRound(curB->round);
//stack loop //stack loop
for(int i=0;i<stacks.size();i++) for(int i=0;i<stacks.size();i++)
@ -200,9 +716,9 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
{ {
unsigned char owner = (stacks[i]->owner)?(hero2 ? hero2->tempOwner : 255):(hero1->tempOwner); unsigned char owner = (stacks[i]->owner)?(hero2 ? hero2->tempOwner : 255):(hero1->tempOwner);
unsigned char serialOwner = -1; unsigned char serialOwner = -1;
for(int g=0; g<CGI->playerint.size(); ++g) for(int g=0; g<VLC->playerint.size(); ++g)
{ {
if(CGI->playerint[g]->playerID == owner) if(VLC->playerint[g]->playerID == owner)
{ {
serialOwner = g; serialOwner = g;
break; break;
@ -211,9 +727,9 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
if(serialOwner==255) //neutral unit if(serialOwner==255) //neutral unit
{ {
} }
else if(CGI->playerint[serialOwner]->human) else if(VLC->playerint[serialOwner]->human)
{ {
BattleAction ba = ((CPlayerInterface*)CGI->playerint[serialOwner])->activeStack(stacks[i]->ID); BattleAction ba = ((CPlayerInterface*)VLC->playerint[serialOwner])->activeStack(stacks[i]->ID);
switch(ba.actionType) switch(ba.actionType)
{ {
case 2: //walk case 2: //walk
@ -226,8 +742,8 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
} }
case 4: //retreat/flee case 4: //retreat/flee
{ {
for(int v=0; v<CGI->playerint.size(); ++v) //tell about the end of this battle to interfaces for(int v=0; v<VLC->playerint.size(); ++v) //tell about the end of this battle to interfaces
CGI->playerint[v]->battleEnd(army1, army2, hero1, hero2, std::vector<int>(), 0, false); VLC->playerint[v]->battleEnd(army1, army2, hero1, hero2, std::vector<int>(), 0, false);
battleEnd = true; battleEnd = true;
break; break;
} }
@ -241,7 +757,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
} }
else else
{ {
//CGI->playerint[serialOwner]->activeStack(stacks[i]->ID); //VLC->playerint[serialOwner]->activeStack(stacks[i]->ID);
} }
} }
if(battleEnd) if(battleEnd)
@ -257,11 +773,11 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
for(int i=0;i<stacks.size();i++) for(int i=0;i<stacks.size();i++)
delete stacks[i]; delete stacks[i];
delete curB; delete curB;
curB = NULL; curB = NULL;*/
} }
bool CGameState::battleMoveCreatureStack(int ID, int dest) bool CGameState::battleMoveCreatureStack(int ID, int dest)
{ {/*
//first checks //first checks
if(curB->stackActionPerformed) //because unit cannot be moved more than once if(curB->stackActionPerformed) //because unit cannot be moved more than once
return false; return false;
@ -435,7 +951,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
} }
else else
{ {
damageBase = rand()%(curStack->creature->damageMax - curStack->creature->damageMin) + curStack->creature->damageMin + 1; damageBase = ran()%(curStack->creature->damageMax - curStack->creature->damageMin) + curStack->creature->damageMin + 1;
} }
float dmgBonusMultiplier = 1.0; float dmgBonusMultiplier = 1.0;
@ -495,7 +1011,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
} }
} }
curB->stackActionPerformed = true; curB->stackActionPerformed = true;
LOCPLINT->actionFinished(BattleAction()); LOCPLINT->actionFinished(BattleAction());*/
return true; return true;
} }
@ -517,7 +1033,7 @@ bool CGameState::battleAttackCreatureStack(int ID, int dest)
} }
std::vector<int> CGameState::battleGetRange(int ID) std::vector<int> CGameState::battleGetRange(int ID)
{ {/*
int initialPlace=-1; //position of unit int initialPlace=-1; //position of unit
int radius=-1; //range of unit int radius=-1; //range of unit
unsigned char owner = -1; //owner of unit unsigned char owner = -1; //owner of unit
@ -681,6 +1197,7 @@ std::vector<int> CGameState::battleGetRange(int ID)
ret2.push_back(*it); ret2.push_back(*it);
} }
return ret2; return ret2;*/
return std::vector<int>();
} }

View File

@ -1,8 +1,8 @@
#ifndef CGAMESTATE_H #ifndef CGAMESTATE_H
#define CGAMESTATE_H #define CGAMESTATE_H
#include "global.h"
#include "mapHandler.h"
#include <set> #include <set>
#include <vector>
#include <tchar.h> #include <tchar.h>
class CScriptCallback; class CScriptCallback;
@ -12,22 +12,30 @@ class CCPPObjectScript;
class CCreatureSet; class CCreatureSet;
class CStack; class CStack;
class CGHeroInstance; class CGHeroInstance;
class CGTownInstance;
class CArmedInstance; class CArmedInstance;
class CGDefInfo;
class CObjectScript;
class CGObjectInstance;
class CCreature;
struct Mapa; struct Mapa;
struct StartInfo;
struct SDL_Surface;
class CMapHandler;
class CPathfinder;
struct PlayerState struct DLL_EXPORT PlayerState
{ {
public: public:
int color, serial; int color, serial;
//std::vector<std::vector<std::vector<char> > > fogOfWarMap; //true - visible, false - hidden std::vector<std::vector<std::vector<unsigned char> > > fogOfWarMap; //true - visible, false - hidden
PseudoV< PseudoV< PseudoV<unsigned char> > > fogOfWarMap; //true - visible, false - hidden
std::vector<int> resources; std::vector<int> resources;
std::vector<CGHeroInstance *> heroes; std::vector<CGHeroInstance *> heroes;
std::vector<CGTownInstance *> towns; std::vector<CGTownInstance *> towns;
PlayerState():color(-1){}; PlayerState():color(-1){};
}; };
struct BattleInfo struct DLL_EXPORT BattleInfo
{ {
int side1, side2; int side1, side2;
int round, activeStack; int round, activeStack;
@ -39,7 +47,7 @@ struct BattleInfo
bool stackActionPerformed; //true if current stack has been moved bool stackActionPerformed; //true if current stack has been moved
}; };
class CStack class DLL_EXPORT CStack
{ {
public: public:
int ID; //unique ID of stack int ID; //unique ID of stack
@ -50,13 +58,14 @@ public:
bool attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle) bool attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle)
int position; //position on battlefield int position; //position on battlefield
bool alive; //true if it is alive bool alive; //true if it is alive
CStack(CCreature * C, int A, int O, int I, bool AO):creature(C),amount(A),owner(O), alive(true), position(-1), ID(I), attackerOwned(AO), firstHPleft(C->hitPoints){}; CStack(CCreature * C, int A, int O, int I, bool AO);
CStack() : creature(NULL),amount(-1),owner(255), alive(true), position(-1), ID(-1), attackerOwned(true), firstHPleft(-1){}; CStack() : creature(NULL),amount(-1),owner(255), alive(true), position(-1), ID(-1), attackerOwned(true), firstHPleft(-1){};
}; };
class CGameState class DLL_EXPORT CGameState
{ {
private: private:
StartInfo* scenarioOps;
int currentPlayer; //ID of player currently having turn int currentPlayer; //ID of player currently having turn
BattleInfo *curB; //current battle BattleInfo *curB; //current battle
int day; //total number of days in game int day; //total number of days in game
@ -65,6 +74,7 @@ private:
std::set<CCPPObjectScript *> cppscripts; //C++ scripts std::set<CCPPObjectScript *> cppscripts; //C++ scripts
std::map<int, std::map<std::string, CObjectScript*> > objscr; //non-C++ scripts std::map<int, std::map<std::string, CObjectScript*> > objscr; //non-C++ scripts
std::map<int, CGDefInfo*> villages, forts, capitols; //def-info for town graphics
bool checkFunc(int obid, std::string name) bool checkFunc(int obid, std::string name)
{ {
@ -77,20 +87,12 @@ private:
} }
return false; return false;
} }
CGHeroInstance * getHero(int ID, int mode)
{ void init(StartInfo * si, Mapa * map, int seed);
if (mode != 0) void randomizeObject(CGObjectInstance *cur);
throw new std::exception("gs->getHero: This mode is not supported!"); std::pair<int,int> pickObject(CGObjectInstance *obj);
for ( std::map<int, PlayerState>::iterator i=players.begin() ; i!=players.end();i++) int pickHero(int owner);
{
for (int j=0;j<(*i).second.heroes.size();j++)
{
if (i->second.heroes[j]->subID == ID)
return i->second.heroes[j];
}
}
return NULL;
}
void battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2); void battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2);
bool battleMoveCreatureStack(int ID, int dest); bool battleMoveCreatureStack(int ID, int dest);
bool battleAttackCreatureStack(int ID, int dest); bool battleAttackCreatureStack(int ID, int dest);
@ -103,7 +105,7 @@ public:
friend void initGameState(Mapa * map, CGameInfo * cgi); friend void initGameState(Mapa * map, CGameInfo * cgi);
friend CScriptCallback; friend CScriptCallback;
friend void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script); friend void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
friend 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); //todo: wywalic koniecznie, tylko do flag obecnie!!!! friend CMapHandler;
}; };
#endif //CGAMESTATE_H #endif //CGAMESTATE_H

View File

@ -24,7 +24,7 @@ CHeroWindow::CHeroWindow(int playerColor):
{ {
artWorn.resize(19); artWorn.resize(19);
background = BitmapHandler::loadBitmap("HEROSCR4.bmp"); background = BitmapHandler::loadBitmap("HEROSCR4.bmp");
CSDL_Ext::blueToPlayersAdv(background, playerColor); graphics->blueToPlayersAdv(background, playerColor);
pos.x = 65; pos.x = 65;
pos.y = 8; pos.y = 8;
pos.h = background->h; pos.h = background->h;

21
CLua.h
View File

@ -11,6 +11,7 @@ class CGHeroInstance;
class CScriptCallback; class CScriptCallback;
class SComponent; class SComponent;
class CSelectableComponent; class CSelectableComponent;
class CGameState;
struct Mapa; struct Mapa;
enum ESLan{UNDEF=-1,CPP,ERM,LUA}; enum ESLan{UNDEF=-1,CPP,ERM,LUA};
class CObjectScript class CObjectScript
@ -70,7 +71,7 @@ public:
void findFS(std::string fname); void findFS(std::string fname);
friend void initGameState(Mapa * map, CGameInfo * cgi); friend CGameState;
}; };
class CLuaObjectScript : public CLua, public CObjectScript class CLuaObjectScript : public CLua, public CObjectScript
@ -85,7 +86,7 @@ public:
void onHeroVisit(CGObjectInstance *os, int heroID); void onHeroVisit(CGObjectInstance *os, int heroID);
std::string hoverText(CGObjectInstance *os); std::string hoverText(CGObjectInstance *os);
friend void initGameState(Mapa * map, CGameInfo * cgi); friend CGameState;
}; };
class CCPPObjectScript: public CObjectScript class CCPPObjectScript: public CObjectScript
{ {
@ -107,7 +108,7 @@ class CVisitableOPH : public CCPPObjectScript //once per hero
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
std::string hoverText(CGObjectInstance *os); std::string hoverText(CGObjectInstance *os);
friend void initGameState(Mapa * map, CGameInfo * cgi); friend CGameState;
}; };
class CVisitableOPW : public CCPPObjectScript //once per week class CVisitableOPW : public CCPPObjectScript //once per week
@ -121,7 +122,7 @@ class CVisitableOPW : public CCPPObjectScript //once per week
std::string hoverText(CGObjectInstance *os); std::string hoverText(CGObjectInstance *os);
void newTurn (); void newTurn ();
friend void initGameState(Mapa * map, CGameInfo * cgi); friend CGameState;
}; };
class CMines : public CCPPObjectScript //flaggable, and giving resource at each day class CMines : public CCPPObjectScript //flaggable, and giving resource at each day
@ -136,7 +137,7 @@ class CMines : public CCPPObjectScript //flaggable, and giving resource at each
std::string hoverText(CGObjectInstance *os); std::string hoverText(CGObjectInstance *os);
void newTurn (); void newTurn ();
friend void initGameState(Mapa * map, CGameInfo * cgi); friend CGameState;
}; };
class CPickable : public CCPPObjectScript, public IChosen //pickable - resources, artifacts, etc class CPickable : public CCPPObjectScript, public IChosen //pickable - resources, artifacts, etc
@ -151,7 +152,7 @@ class CPickable : public CCPPObjectScript, public IChosen //pickable - resource
std::string hoverText(CGObjectInstance *os); std::string hoverText(CGObjectInstance *os);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
friend void initGameState(Mapa * map, CGameInfo * cgi); friend CGameState;
}; };
class CTownScript : public CCPPObjectScript //pickable - resources, artifacts, etc class CTownScript : public CCPPObjectScript //pickable - resources, artifacts, etc
@ -162,7 +163,7 @@ class CTownScript : public CCPPObjectScript //pickable - resources, artifacts,
std::string hoverText(CGObjectInstance *os); std::string hoverText(CGObjectInstance *os);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
friend void initGameState(Mapa * map, CGameInfo * cgi); friend CGameState;
}; };
class CHeroScript : public CCPPObjectScript class CHeroScript : public CCPPObjectScript
@ -174,7 +175,7 @@ class CHeroScript : public CCPPObjectScript
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
std::string hoverText(CGObjectInstance *os); std::string hoverText(CGObjectInstance *os);
friend void initGameState(Mapa * map, CGameInfo * cgi); friend CGameState;
}; };
class CMonsterS : public CCPPObjectScript class CMonsterS : public CCPPObjectScript
@ -186,7 +187,7 @@ class CMonsterS : public CCPPObjectScript
void onHeroVisit(CGObjectInstance *os, int heroID); void onHeroVisit(CGObjectInstance *os, int heroID);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
friend void initGameState(Mapa * map, CGameInfo * cgi); friend CGameState;
}; };
class CCreatureGen : public CCPPObjectScript class CCreatureGen : public CCPPObjectScript
@ -198,5 +199,5 @@ class CCreatureGen : public CCPPObjectScript
void onHeroVisit(CGObjectInstance *os, int heroID); void onHeroVisit(CGObjectInstance *os, int heroID);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
friend void initGameState(Mapa * map, CGameInfo * cgi); friend CGameState;
}; };

368
CMT.cpp
View File

@ -9,14 +9,10 @@
#include "SDL_Extensions.h" #include "SDL_Extensions.h"
#include "SDL_framerate.h" #include "SDL_framerate.h"
#include <cmath> #include <cmath>
#include <stdio.h>
#include <string.h>
#include <string> #include <string>
#include <assert.h>
#include <vector> #include <vector>
#include "zlib.h" #include "zlib.h"
#include <cmath> #include <cmath>
#include <ctime>
#include "hch\CArtHandler.h" #include "hch\CArtHandler.h"
#include "hch\CHeroHandler.h" #include "hch\CHeroHandler.h"
#include "hch\CCreatureHandler.h" #include "hch\CCreatureHandler.h"
@ -28,7 +24,6 @@
#include "hch\CMusicHandler.h" #include "hch\CMusicHandler.h"
#include "hch\CLodHandler.h" #include "hch\CLodHandler.h"
#include "hch\CDefHandler.h" #include "hch\CDefHandler.h"
#include "hch\CSndHandler.h"
#include "hch\CTownHandler.h" #include "hch\CTownHandler.h"
#include "hch\CDefObjInfoHandler.h" #include "hch\CDefObjInfoHandler.h"
#include "hch\CAmbarCendamo.h" #include "hch\CAmbarCendamo.h"
@ -46,12 +41,11 @@
#include "CLuaHandler.h" #include "CLuaHandler.h"
#include "CLua.h" #include "CLua.h"
#include "CAdvmapInterface.h" #include "CAdvmapInterface.h"
#include "CCastleInterface.h"
#include "client\Graphics.h" #include "client\Graphics.h"
const char * NAME = "VCMI \"Altanatse\" 0.7"; #include <boost/asio.hpp>
std::string NAME = NAME_VER + std::string(" (client)");
DLL_EXPORT void initDLL(CLodHandler *b); DLL_EXPORT void initDLL(CLodHandler *b);
SDL_Color playerColorPalette[256]; //palette to make interface colors good using boost::asio::ip::tcp;
SDL_Surface * screen, * screen2; SDL_Surface * screen, * screen2;
extern SDL_Surface * CSDL_Ext::std32bppSurface; extern SDL_Surface * CSDL_Ext::std32bppSurface;
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
@ -64,258 +58,30 @@ void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * sc
} }
CGI->state->cppscripts.insert(script); CGI->state->cppscripts.insert(script);
} }
void initGameState(Mapa * map, CGameInfo * cgi)
{
cgi->state->day=0;
/*********creating players entries in gs****************************************/
for (int i=0; i<cgi->scenarioOps.playerInfos.size();i++)
{
std::pair<int,PlayerState> ins(cgi->scenarioOps.playerInfos[i].color,PlayerState());
ins.second.color=ins.first;
ins.second.serial=i;
cgi->state->players.insert(ins);
}
/******************RESOURCES****************************************************/
//TODO: zeby komputer dostawal inaczej niz gracz
std::vector<int> startres;
std::ifstream tis("config/startres.txt");
int k;
for (int j=0;j<cgi->scenarioOps.difficulty;j++)
{
tis >> k;
for (int z=0;z<RESOURCE_QUANTITY;z++)
tis>>k;
}
tis >> k;
for (int i=0;i<RESOURCE_QUANTITY;i++)
{
tis >> k;
startres.push_back(k);
}
tis.close();
for (std::map<int,PlayerState>::iterator i = cgi->state->players.begin(); i!=cgi->state->players.end(); i++)
{
(*i).second.resources.resize(RESOURCE_QUANTITY);
for (int x=0;x<RESOURCE_QUANTITY;x++)
(*i).second.resources[x] = startres[x];
}
/*************************HEROES************************************************/
for (int i=0; i<map->heroes.size();i++) //heroes instances
{
if (map->heroes[i]->getOwner()<0)
continue;
CGHeroInstance * vhi = (map->heroes[i]);
if(!vhi->type)
vhi->type = cgi->heroh->heroes[vhi->subID];
//vhi->subID = vhi->type->ID;
if (vhi->level<1)
{
vhi->exp=40+rand()%50;
vhi->level = 1;
}
if (vhi->level>1) ;//TODO dodac um dr, ale potrzebne los
if ((!vhi->primSkills.size()) || (vhi->primSkills[0]<0))
{
if (vhi->primSkills.size()<PRIMARY_SKILLS)
vhi->primSkills.resize(PRIMARY_SKILLS);
vhi->primSkills[0] = vhi->type->heroClass->initialAttack;
vhi->primSkills[1] = vhi->type->heroClass->initialDefence;
vhi->primSkills[2] = vhi->type->heroClass->initialPower;
vhi->primSkills[3] = vhi->type->heroClass->initialKnowledge;
}
vhi->mana = vhi->primSkills[3]*10;
if (!vhi->name.length())
{
vhi->name = vhi->type->name;
}
if (!vhi->biography.length())
{
vhi->biography = vhi->type->biography;
}
if (vhi->portrait < 0)
vhi->portrait = vhi->type->ID;
//initial army
if (!vhi->army.slots.size()) //standard army
{
int pom, pom2=0;
for(int x=0;x<3;x++)
{
pom = (cgi->creh->nameToID[vhi->type->refTypeStack[x]]);
if(pom>=145 && pom<=149) //war machine
{
pom2++;
switch (pom)
{
case 145: //catapult
vhi->artifWorn[16] = 3;
break;
default:
pom-=145;
vhi->artifWorn[13+pom] = 4+pom;
break;
}
continue;
}
vhi->army.slots[x-pom2].first = &(cgi->creh->creatures[pom]);
if((pom = (vhi->type->highStack[x]-vhi->type->lowStack[x])) > 0)
vhi->army.slots[x-pom2].second = (rand()%pom)+vhi->type->lowStack[x];
else
vhi->army.slots[x-pom2].second = +vhi->type->lowStack[x];
}
}
cgi->state->players[vhi->getOwner()].heroes.push_back(vhi);
}
/*************************FOG**OF**WAR******************************************/
for(std::map<int, PlayerState>::iterator k=cgi->state->players.begin(); k!=cgi->state->players.end(); ++k)
{
k->second.fogOfWarMap.resize(map->width, Woff);
for(int g=-Woff; g<map->width+Woff; ++g)
k->second.fogOfWarMap[g].resize(map->height, Hoff);
for(int g=-Woff; g<map->width+Woff; ++g)
for(int h=-Hoff; h<map->height+Hoff; ++h)
k->second.fogOfWarMap[g][h].resize(map->twoLevel+1, 0);
for(int g=-Woff; g<map->width+Woff; ++g)
for(int h=-Hoff; h<map->height+Hoff; ++h)
for(int v=0; v<map->twoLevel+1; ++v)
k->second.fogOfWarMap[g][h][v] = 0;
for(int xd=0; xd<map->width; ++xd) //revealing part of map around heroes
{
for(int yd=0; yd<map->height; ++yd)
{
for(int ch=0; ch<k->second.heroes.size(); ++ch)
{
int deltaX = (k->second.heroes[ch]->getPosition(false).x-xd)*(k->second.heroes[ch]->getPosition(false).x-xd);
int deltaY = (k->second.heroes[ch]->getPosition(false).y-yd)*(k->second.heroes[ch]->getPosition(false).y-yd);
if(deltaX+deltaY<k->second.heroes[ch]->getSightDistance()*k->second.heroes[ch]->getSightDistance())
k->second.fogOfWarMap[xd][yd][k->second.heroes[ch]->getPosition(false).z] = 1;
}
}
}
}
/****************************TOWNS************************************************/
for (int i=0;i<map->towns.size();i++)
{
CGTownInstance * vti =(map->towns[i]);
if(!vti->town)
vti->town = &CGI->townh->towns[vti->subID];
if (vti->name.length()==0) // if town hasn't name we draw it
vti->name=vti->town->names[rand()%vti->town->names.size()];
if(vti->builtBuildings.find(-50)!=vti->builtBuildings.end()) //give standard set of buildings
{
vti->builtBuildings.erase(-50);
vti->builtBuildings.insert(10);
vti->builtBuildings.insert(5);
vti->builtBuildings.insert(30);
if(rand()%2)
vti->builtBuildings.insert(31);
}
cgi->state->players[vti->getOwner()].towns.push_back(vti);
}
for(std::map<int, PlayerState>::iterator k=cgi->state->players.begin(); k!=cgi->state->players.end(); ++k)
{
if(k->first==-1 || k->first==255)
continue;
for(int xd=0; xd<map->width; ++xd) //revealing part of map around towns
{
for(int yd=0; yd<map->height; ++yd)
{
for(int ch=0; ch<k->second.towns.size(); ++ch)
{
int deltaX = (k->second.towns[ch]->pos.x-xd)*(k->second.towns[ch]->pos.x-xd);
int deltaY = (k->second.towns[ch]->pos.y-yd)*(k->second.towns[ch]->pos.y-yd);
if(deltaX+deltaY<k->second.towns[ch]->getSightDistance()*k->second.towns[ch]->getSightDistance())
k->second.fogOfWarMap[xd][yd][k->second.towns[ch]->pos.z] = 1;
}
}
}
//init visiting heroes
for(int l=0; l<k->second.heroes.size();l++)
{
for(int m=0; m<k->second.towns.size();m++)
{
int3 vistile = k->second.towns[m]->pos; vistile.x--; //tile next to the entrance
if(vistile == k->second.heroes[l]->pos)
{
k->second.towns[m]->visitingHero = k->second.heroes[l];
break;
}
}
}
}
/****************************SCRIPTS************************************************/
std::map<int, std::map<std::string, CObjectScript*> > * skrypty = &cgi->state->objscr; //alias for easier access
/****************************C++ OBJECT SCRIPTS************************************************/
std::map<int,CCPPObjectScript*> scripts;
CScriptCallback * csc = new CScriptCallback();
csc->gs = cgi->state;
handleCPPObjS(&scripts,new CVisitableOPH(csc));
handleCPPObjS(&scripts,new CVisitableOPW(csc));
handleCPPObjS(&scripts,new CPickable(csc));
handleCPPObjS(&scripts,new CMines(csc));
handleCPPObjS(&scripts,new CTownScript(csc));
handleCPPObjS(&scripts,new CHeroScript(csc));
handleCPPObjS(&scripts,new CMonsterS(csc));
handleCPPObjS(&scripts,new CCreatureGen(csc));
//created map
/****************************LUA OBJECT SCRIPTS************************************************/
std::vector<std::string> * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files
for (int i=0; i<lf->size(); i++)
{
try
{
std::vector<std::string> * temp = CLuaHandler::functionList((*lf)[i]);
CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]);
CLuaCallback::registerFuncs(objs->is);
//objs
for (int j=0; j<temp->size(); j++)
{
int obid ; //obj ID
int dspos = (*temp)[j].find_first_of('_');
obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str());
std::string fname = (*temp)[j].substr(0,dspos);
if (skrypty->find(obid)==skrypty->end())
skrypty->insert(std::pair<int, std::map<std::string, CObjectScript*> >(obid,std::map<std::string,CObjectScript*>()));
(*skrypty)[obid].insert(std::pair<std::string, CObjectScript*>(fname,objs));
}
delete temp;
}HANDLE_EXCEPTION
}
/****************************INITIALIZING OBJECT SCRIPTS************************************************/
std::string temps("newObject");
for (int i=0; i<map->objects.size(); i++)
{
//c++ scripts
if (scripts.find(map->objects[i]->ID) != scripts.end())
{
map->objects[i]->state = scripts[map->objects[i]->ID];
map->objects[i]->state->newObject(map->objects[i]);
}
else
{
map->objects[i]->state = NULL;
}
// lua scripts
if(cgi->state->checkFunc(map->objects[i]->ID,temps))
(*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]);
}
delete lf;
}
int _tmain(int argc, _TCHAR* argv[]) int _tmain(int argc, _TCHAR* argv[])
{ { /*
boost::asio::io_service io_service;
boost::system::error_code error = boost::asio::error::host_not_found;
tcp::socket socket(io_service);
tcp::resolver resolver(io_service);
tcp::resolver::query query("127.0.0.1", "3030");
tcp::resolver::iterator endpoint_iterator = resolver.resolve(tcp::resolver::query("127.0.0.1", "3030"));
socket.connect(*endpoint_iterator, error);
boost::array<char, 128> buf;
size_t len = socket.read_some(boost::asio::buffer(buf), error);
if (error == boost::asio::error::eof)
; // Connection closed cleanly by peer.
else if (error)
throw boost::system::system_error(error); // Some other error.
std::cout.write(buf.data(), len);
len = socket.read_some(boost::asio::buffer(buf), error);
std::cout.write(buf.data(), len);*/
srand ( time(NULL) ); srand ( time(NULL) );
CPG=NULL; CPG=NULL;
atexit(SDL_Quit); atexit(SDL_Quit);
@ -330,7 +96,7 @@ int _tmain(int argc, _TCHAR* argv[])
{ {
screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); //initializing important global surface screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); //initializing important global surface
THC std::cout<<"\tInitializing screen: "<<pomtime.getDif()<<std::endl; THC std::cout<<"\tInitializing screen: "<<pomtime.getDif()<<std::endl;
SDL_WM_SetCaption(NAME,""); //set window title SDL_WM_SetCaption(NAME.c_str(),""); //set window title
#if SDL_BYTEORDER == SDL_BIG_ENDIAN #if SDL_BYTEORDER == SDL_BIG_ENDIAN
int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff; int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff;
#else #else
@ -390,43 +156,6 @@ int _tmain(int argc, _TCHAR* argv[])
graphics->loadHeroAnim(animacje); graphics->loadHeroAnim(animacje);
THC std::cout<<"\tHero animations: "<<tmh.getDif()<<std::endl; THC std::cout<<"\tHero animations: "<<tmh.getDif()<<std::endl;
THC std::cout<<"Initializing game graphics: "<<tmh.getDif()<<std::endl; THC std::cout<<"Initializing game graphics: "<<tmh.getDif()<<std::endl;
//colors initialization
SDL_Color p;
p.unused = 0;
p.r = 0xff; p.g = 0x0; p.b = 0x0; //red
cgi->playerColors.push_back(p); //red
p.r = 0x31; p.g = 0x52; p.b = 0xff; //blue
cgi->playerColors.push_back(p); //blue
p.r = 0x9c; p.g = 0x73; p.b = 0x52;//tan
cgi->playerColors.push_back(p);//tan
p.r = 0x42; p.g = 0x94; p.b = 0x29; //green
cgi->playerColors.push_back(p); //green
p.r = 0xff; p.g = 0x84; p.b = 0x0; //orange
cgi->playerColors.push_back(p); //orange
p.r = 0x8c; p.g = 0x29; p.b = 0xa5; //purple
cgi->playerColors.push_back(p); //purple
p.r = 0x09; p.g = 0x9c; p.b = 0xa5;//teal
cgi->playerColors.push_back(p);//teal
p.r = 0xc6; p.g = 0x7b; p.b = 0x8c;//pink
cgi->playerColors.push_back(p);//pink
p.r = 0x84; p.g = 0x84; p.b = 0x84;//gray
cgi->neutralColor = p;//gray
//colors initialized
//palette initialization
std::string pals = cgi->bitmaph->getTextFile("PLAYERS.PAL");
int startPoint = 24; //beginning byte; used to read
for(int i=0; i<256; ++i)
{
SDL_Color col;
col.r = pals[startPoint++];
col.g = pals[startPoint++];
col.b = pals[startPoint++];
col.unused = pals[startPoint++];
playerColorPalette[i] = col;
}
//palette initialized
THC std::cout<<"Preparing players' colours: "<<tmh.getDif()<<std::endl;
CMessage::init(); CMessage::init();
cgi->generaltexth = new CGeneralTextHandler; cgi->generaltexth = new CGeneralTextHandler;
cgi->generaltexth->load(); cgi->generaltexth->load();
@ -435,8 +164,17 @@ int _tmain(int argc, _TCHAR* argv[])
THC std::cout<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl; THC std::cout<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl;
THC std::cout<<"Initialization of VCMI (togeter): "<<total.getDif()<<std::endl; THC std::cout<<"Initialization of VCMI (togeter): "<<total.getDif()<<std::endl;
cpg->mush = mush; cpg->mush = mush;
cgi->scenarioOps = cpg->runLoop(); StartInfo *options = new StartInfo(cpg->runLoop());
THC tmh.getDif();pomtime.getDif();
cgi->dobjinfo = new CDefObjInfoHandler;
cgi->dobjinfo->load();
THC std::cout<<"\tDef information handler: "<<pomtime.getDif()<<std::endl;
cgi->state = new CGameState();
cgi->state->scenarioOps = options;
THC std::cout<<"\tGamestate: "<<pomtime.getDif()<<std::endl;
THC tmh.getDif();pomtime.getDif();//reset timers
CArtHandler * arth = new CArtHandler; CArtHandler * arth = new CArtHandler;
arth->loadArtifacts(); arth->loadArtifacts();
cgi->arth = arth; cgi->arth = arth;
@ -462,20 +200,13 @@ int _tmain(int argc, _TCHAR* argv[])
cgi->objh = objh; cgi->objh = objh;
THC std::cout<<"\tObject handler: "<<pomtime.getDif()<<std::endl; THC std::cout<<"\tObject handler: "<<pomtime.getDif()<<std::endl;
cgi->dobjinfo = new CDefObjInfoHandler;
cgi->dobjinfo->load();
THC std::cout<<"\tDef information handler: "<<pomtime.getDif()<<std::endl;
cgi->state = new CGameState();
cgi->state->players = std::map<int, PlayerState>();
THC std::cout<<"\tGamestate: "<<pomtime.getDif()<<std::endl;
cgi->pathf = new CPathfinder(); cgi->pathf = new CPathfinder();
THC std::cout<<"\tPathfinder: "<<pomtime.getDif()<<std::endl; THC std::cout<<"\tPathfinder: "<<pomtime.getDif()<<std::endl;
cgi->consoleh->cb = new CCallback(cgi->state,-1); cgi->consoleh->cb = new CCallback(cgi->state,-1);
cgi->consoleh->runConsole(); cgi->consoleh->runConsole();
THC std::cout<<"\tCallback and console: "<<pomtime.getDif()<<std::endl; THC std::cout<<"\tCallback and console: "<<pomtime.getDif()<<std::endl;
THC std::cout<<"Handlers initailization (together): "<<tmh.getDif()<<std::endl; THC std::cout<<"Handlers initialization (together): "<<tmh.getDif()<<std::endl;
std::string mapname = cpg->ourScenSel->mapsel.ourMaps[cpg->ourScenSel->mapsel.selected].filename; std::string mapname = cpg->ourScenSel->mapsel.ourMaps[cpg->ourScenSel->mapsel.selected].filename;
std::cout<<"Opening map file: "<<mapname<<"\t\t"<<std::flush; std::cout<<"Opening map file: "<<mapname<<"\t\t"<<std::flush;
@ -494,8 +225,11 @@ int _tmain(int argc, _TCHAR* argv[])
std::cout<<"done."<<std::endl; std::cout<<"done."<<std::endl;
Mapa * mapa = new Mapa(initTable); Mapa * mapa = new Mapa(initTable);
THC std::cout<<"Reading and detecting map file (together): "<<tmh.getDif()<<std::endl; THC std::cout<<"Reading and detecting map file (together): "<<tmh.getDif()<<std::endl;
CMapHandler * mh = new CMapHandler();
cgi->mh = mh; cgi->state->init(options,mapa,8);
CMapHandler * mh = cgi->mh = new CMapHandler();
THC std::cout<<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
mh->map = mapa; mh->map = mapa;
THC std::cout<<"Creating mapHandler: "<<tmh.getDif()<<std::endl; THC std::cout<<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
mh->loadDefs(); mh->loadDefs();
@ -503,18 +237,16 @@ int _tmain(int argc, _TCHAR* argv[])
mh->init(); mh->init();
THC std::cout<<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl; THC std::cout<<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
initGameState(mapa,cgi); for (int i=0; i<cgi->state->scenarioOps->playerInfos.size();i++) //initializing interfaces
THC std::cout<<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
for (int i=0; i<cgi->scenarioOps.playerInfos.size();i++) //initializing interfaces
{ {
if(!cgi->scenarioOps.playerInfos[i].human) if(!cgi->state->scenarioOps->playerInfos[i].human)
cgi->playerint.push_back(static_cast<CGameInterface*>(CAIHandler::getNewAI(new CCallback(cgi->state,cgi->scenarioOps.playerInfos[i].color),"EmptyAI.dll"))); cgi->playerint.push_back(static_cast<CGameInterface*>(CAIHandler::getNewAI(new CCallback(cgi->state,cgi->state->scenarioOps->playerInfos[i].color),"EmptyAI.dll")));
else else
{ {
cgi->state->currentPlayer=cgi->scenarioOps.playerInfos[i].color; cgi->state->currentPlayer=cgi->state->scenarioOps->playerInfos[i].color;
cgi->playerint.push_back(new CPlayerInterface(cgi->scenarioOps.playerInfos[i].color,i)); cgi->playerint.push_back(new CPlayerInterface(cgi->state->scenarioOps->playerInfos[i].color,i));
((CPlayerInterface*)(cgi->playerint[i]))->init(new CCallback(cgi->state,cgi->scenarioOps.playerInfos[i].color)); ((CPlayerInterface*)(cgi->playerint[i]))->init(new CCallback(cgi->state,cgi->state->scenarioOps->playerInfos[i].color));
} }
} }
///claculating FoWs for minimap ///claculating FoWs for minimap

View File

@ -14,6 +14,7 @@
#include <sstream> #include <sstream>
#include "CLua.h" #include "CLua.h"
#include "hch/CGeneralTextHandler.h" #include "hch/CGeneralTextHandler.h"
#include "client/Graphics.h"
SDL_Color tytulowy, tlo, zwykly ; SDL_Color tytulowy, tlo, zwykly ;
SDL_Rect genRect(int hh, int ww, int xx, int yy); SDL_Rect genRect(int hh, int ww, int xx, int yy);
@ -61,7 +62,7 @@ void CMessage::init()
} }
for (int j=0;j<bluePieces->ourImages.size();j++) for (int j=0;j<bluePieces->ourImages.size();j++)
{ {
CSDL_Ext::blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i); graphics->blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i);
piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap); piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
} }
} }

View File

@ -2717,7 +2717,7 @@ CRecrutationWindow::CRecrutationWindow(const std::vector<std::pair<int,int> > &C
amounts[i] = CGI->creh->creatures[Creatures[i].first].maxAmount(LOCPLINT->cb->getResourceAmount()); amounts[i] = CGI->creh->creatures[Creatures[i].first].maxAmount(LOCPLINT->cb->getResourceAmount());
} }
SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPRCRT.bmp"); SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPRCRT.bmp");
blueToPlayersAdv(hhlp,LOCPLINT->playerID); graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID);
bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo
SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255)); SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
SDL_FreeSurface(hhlp); SDL_FreeSurface(hhlp);
@ -2884,7 +2884,7 @@ CCreInfoWindow::CCreInfoWindow
pos.y = screen->h/2 - bitmap->h/2; pos.y = screen->h/2 - bitmap->h/2;
pos.w = bitmap->w; pos.w = bitmap->w;
pos.h = bitmap->h; pos.h = bitmap->h;
blueToPlayersAdv(bitmap,LOCPLINT->playerID); graphics->blueToPlayersAdv(bitmap,LOCPLINT->playerID);
SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255)); SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
anim = new CCreaturePic(c); anim = new CCreaturePic(c);
if(!type) anim->anim->setType(1); if(!type) anim->anim->setType(1);

View File

@ -9,8 +9,7 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include "hch\CDefHandler.h" #include "hch\CDefHandler.h"
#include <map> #include <map>
#include "client\Graphics.h"
extern SDL_Color playerColorPalette[256];
SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given
{ {
@ -403,45 +402,6 @@ SDL_Surface * CSDL_Ext::rotate03(SDL_Surface * toRot)
} }
return ret; return ret;
} }
//converts surface to cursor
SDL_Cursor * CSDL_Ext::SurfaceToCursor(SDL_Surface *image, int hx, int hy)
{
int w, x, y;
Uint8 *data, *mask, *d, *m, r, g, b;
Uint32 color;
SDL_Cursor *cursor;
w = (image->w + 7) / 8;
data = (Uint8 *)alloca(w * image->h * 2);
if (data == NULL)
return NULL;
memset(data, 0, w * image->h * 2);
mask = data + w * image->h;
if (SDL_MUSTLOCK(image))
SDL_LockSurface(image);
for (y = 0; y < image->h; y++)
{
d = data + y * w;
m = mask + y * w;
for (x = 0; x < image->w; x++)
{
color = CSDL_Ext::SDL_GetPixel(image, x, y);
if ((image->flags & SDL_SRCCOLORKEY) == 0 || color != image->format->colorkey)
{
SDL_GetRGB(color, image->format, &r, &g, &b);
color = (r + g + b) / 3;
m[x / 8] |= 128 >> (x & 7);
if (color < 128)
d[x / 8] |= 128 >> (x & 7);
}
}
}
if (SDL_MUSTLOCK(image))
SDL_UnlockSurface(image);
cursor = SDL_CreateCursor(data, mask, w, image->h, hx, hy);
return cursor;
}
Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte) Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte)
{ {
int bpp = surface->format->BytesPerPixel; int bpp = surface->format->BytesPerPixel;
@ -471,7 +431,7 @@ Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y
return *(Uint32 *)p; return *(Uint32 *)p;
default: default:
return 0; /* shouldn't happen, but avoids warnings */ return 0; // shouldn't happen, but avoids warnings
} }
} }
@ -530,11 +490,6 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src)
return src; return src;
} }
SDL_Surface * CSDL_Ext::secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha)
{
return copySurface(src);
}
int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect) int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)
{ {
static std::map<Uint8, int> st; static std::map<Uint8, int> st;
@ -732,128 +687,6 @@ void CSDL_Ext::update(SDL_Surface * what)
if(what) if(what)
SDL_UpdateRect(what, 0, 0, what->w, what->h); SDL_UpdateRect(what, 0, 0, what->w, what->h);
} }
void CSDL_Ext::blueToPlayers(SDL_Surface * sur, int player)
{
if(sur->format->BitsPerPixel == 8)
{
for(int i=0; i<sur->format->palette->ncolors; ++i)
{
SDL_Color * cc = sur->format->palette->colors+i;
if(cc->r==0 && cc->g==0 && cc->b==255)
{
cc->r = CGI->playerColors[player].r;
cc->g = CGI->playerColors[player].g;
cc->b = CGI->playerColors[player].b;
}
}
}
else if(sur->format->BitsPerPixel == 24)
{
for(int y=0; y<sur->h; ++y)
{
for(int x=0; x<sur->w; ++x)
{
Uint8* cp = (Uint8*)sur->pixels + y+sur->pitch + x*3;
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
{
if(cp[0]==0 && cp[1]==0 && cp[2]==255)
{
cp[0] = CGI->playerColors[player].r;
cp[1] = CGI->playerColors[player].g;
cp[2] = CGI->playerColors[player].b;
}
}
else
{
if(cp[0]==255 && cp[1]==0 && cp[2]==0)
{
cp[0] = CGI->playerColors[player].b;
cp[1] = CGI->playerColors[player].g;
cp[2] = CGI->playerColors[player].r;
}
}
}
}
}
}
void CSDL_Ext::blueToPlayersAdv(SDL_Surface * sur, int player, int mode, void* additionalInfo)
{
if(player==1) //it is actually blue...
return;
if(sur->format->BitsPerPixel == 8)
{
for(int i=0; i<32; ++i)
{
sur->format->palette->colors[224+i] = playerColorPalette[32*player+i];
}
}
else if(sur->format->BitsPerPixel == 24) //should never happen in general
{
for(int y=0; y<sur->h; ++y)
{
for(int x=0; x<sur->w; ++x)
{
Uint8* cp = (Uint8*)sur->pixels + y*sur->pitch + x*3;
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
{
if(cp[2]>cp[1] && cp[2]>cp[0])
{
std::vector<long long int> sort1;
sort1.push_back(cp[0]);
sort1.push_back(cp[1]);
sort1.push_back(cp[2]);
std::vector< std::pair<long long int, Uint8*> > sort2;
sort2.push_back(std::make_pair(CGI->playerColors[player].r, &(cp[0])));
sort2.push_back(std::make_pair(CGI->playerColors[player].g, &(cp[1])));
sort2.push_back(std::make_pair(CGI->playerColors[player].b, &(cp[2])));
std::sort(sort1.begin(), sort1.end());
if(sort2[0].first>sort2[1].first)
std::swap(sort2[0], sort2[1]);
if(sort2[1].first>sort2[2].first)
std::swap(sort2[1], sort2[2]);
if(sort2[0].first>sort2[1].first)
std::swap(sort2[0], sort2[1]);
for(int hh=0; hh<3; ++hh)
{
(*sort2[hh].second) = (sort1[hh] + sort2[hh].first)/2.2;
}
}
}
else
{
if(
((mode==0) && (cp[0]>cp[1]) && (cp[0]>cp[2])) ||
((mode==1) && (cp[2]<45) && (cp[0]>80) && (cp[1]<70) && ((cp[0]-cp[1])>40))
)
{
std::vector<long long int> sort1;
sort1.push_back(cp[2]);
sort1.push_back(cp[1]);
sort1.push_back(cp[0]);
std::vector< std::pair<long long int, Uint8*> > sort2;
sort2.push_back(std::make_pair(CGI->playerColors[player].r, &(cp[2])));
sort2.push_back(std::make_pair(CGI->playerColors[player].g, &(cp[1])));
sort2.push_back(std::make_pair(CGI->playerColors[player].b, &(cp[0])));
std::sort(sort1.begin(), sort1.end());
if(sort2[0].first>sort2[1].first)
std::swap(sort2[0], sort2[1]);
if(sort2[1].first>sort2[2].first)
std::swap(sort2[1], sort2[2]);
if(sort2[0].first>sort2[1].first)
std::swap(sort2[0], sort2[1]);
for(int hh=0; hh<3; ++hh)
{
(*sort2[hh].second) = (sort1[hh]*0.8 + sort2[hh].first)/2;
}
}
}
}
}
}
}
void CSDL_Ext::drawBorder(SDL_Surface * sur, int x, int y, int w, int h, int3 color) void CSDL_Ext::drawBorder(SDL_Surface * sur, int x, int y, int w, int h, int3 color)
{ {
for(int i=0;i<w;i++) for(int i=0;i<w;i++)
@ -874,9 +707,9 @@ void CSDL_Ext::setPlayerColor(SDL_Surface * sur, unsigned char player)
if(sur->format->BitsPerPixel==8) if(sur->format->BitsPerPixel==8)
{ {
if(player != 255) if(player != 255)
*(sur->format->palette->colors+5) = CGI->playerColors[player]; *(sur->format->palette->colors+5) = graphics->playerColors[player];
else else
*(sur->format->palette->colors+5) = CGI->neutralColor; *(sur->format->palette->colors+5) = *graphics->neutralColor;
} }
} }
int readNormalNr (std::istream &in, int bytCon) int readNormalNr (std::istream &in, int bytCon)
@ -897,15 +730,6 @@ int readNormalNr (std::istream &in, int bytCon)
return ret; return ret;
} }
//void CSDL_Ext::fullAlphaTransform(SDL_Surface *& src)
//{
// src = alphaTransform(src);
// //SDL_Surface * hlp2;
// //hlp2 = secondAlphaTransform(src, std32bppSurface);
// //SDL_FreeSurface(src);
// //src = hlp2;
//}
std::string CSDL_Ext::processStr(std::string str, std::vector<std::string> & tor) std::string CSDL_Ext::processStr(std::string str, std::vector<std::string> & tor)
{ {
for (int i=0;(i<tor.size())&&(boost::find_first(str,"%s"));i++) for (int i=0;(i<tor.size())&&(boost::find_first(str,"%s"));i++)

View File

@ -34,9 +34,7 @@ namespace CSDL_Ext
Uint32 SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte = false); Uint32 SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte = false);
SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y); SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y);
SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details) SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details)
SDL_Surface * secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha); //alpha is a surface we want to blit src to
int blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface int blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface
//void fullAlphaTransform(SDL_Surface *& src); //performs first and second alpha transform
Uint32 colorToUint32(const SDL_Color * color); //little endian only Uint32 colorToUint32(const SDL_Color * color); //little endian only
void printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y) void printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)
void printToWR(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y) void printToWR(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)
@ -45,10 +43,6 @@ namespace CSDL_Ext
void printAtWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen); void printAtWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest
void update(SDL_Surface * what = screen); //updates whole surface (default - main screen) void update(SDL_Surface * what = screen); //updates whole surface (default - main screen)
void blueToPlayers(SDL_Surface * sur, int player); //simple color substitution
void blueToPlayersAdv(SDL_Surface * sur, int player, int mode=0, void* additionalInfo=NULL); //substitute blue color by another one, makes it nicer keeping nuances
//mode 1 is calibrated for hero infobox
//mode 2 is calibrated for resbar and gets in additionalInfo a pointer to the set of (SDL_Color) which shouldn't be replaced
void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, int3 color); void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, int3 color);
void setPlayerColor(SDL_Surface * sur, unsigned char player); //sets correct color of flags; -1 for neutral void setPlayerColor(SDL_Surface * sur, unsigned char player); //sets correct color of flags; -1 for neutral
std::string processStr(std::string str, std::vector<std::string> & tor); //replaces %s in string std::string processStr(std::string str, std::vector<std::string> & tor); //replaces %s in string

File diff suppressed because it is too large Load Diff

View File

@ -1,117 +0,0 @@
/*
SDL_rotozoom - rotozoomer
LGPL (c) A. Schiffler
*/
#ifndef _SDL_rotozoom_h
#define _SDL_rotozoom_h
#include <math.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifndef M_PI
#define M_PI 3.141592654
#endif
#include "SDL.h"
/* ---- Defines */
#define SMOOTHING_OFF 0
#define SMOOTHING_ON 1
/* ---- Structures */
typedef struct tColorRGBA {
Uint8 r;
Uint8 g;
Uint8 b;
Uint8 a;
} tColorRGBA;
typedef struct tColorY {
Uint8 y;
} tColorY;
/* ---- Prototypes */
#ifdef WIN32
#ifdef BUILD_DLL
#define DLLINTERFACE __declspec(dllexport)
#else
#define DLLINTERFACE __declspec(dllimport)
#endif
#else
#define DLLINTERFACE
#endif
/*
rotozoomSurface()
Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface.
'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1
then the destination 32bit surface is anti-aliased. If the surface is not 8bit
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
*/
SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth);
SDL_Surface *rotozoomSurfaceXY
(SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth);
/* Returns the size of the target surface for a rotozoomSurface() call */
void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth,
int *dstheight);
void rotozoomSurfaceSizeXY
(int width, int height, double angle, double zoomx, double zoomy,
int *dstwidth, int *dstheight);
/*
zoomSurface()
Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface.
'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is 1
then the destination 32bit surface is anti-aliased. If the surface is not 8bit
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
*/
SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth);
/* Returns the size of the target surface for a zoomSurface() call */
void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight);
/*
shrinkSurface()
Shrinks a 32bit or 8bit 'src' surface ti a newly created 'dst' surface.
'factorx' and 'factory' are the shrinking ratios (i.e. 2=1/2 the size,
3=1/3 the size, etc.) The destination surface is antialiased by averaging
the source box RGBA or Y information. If the surface is not 8bit
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
*/
SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* _SDL_rotozoom_h */

View File

@ -2,7 +2,6 @@
#include "Graphics.h" #include "Graphics.h"
#include "../hch/CDefHandler.h" #include "../hch/CDefHandler.h"
#include "../hch/CObjectHandler.h" #include "../hch/CObjectHandler.h"
//#include "../hch/CHeroHandler.h"
#include "../SDL_Extensions.h" #include "../SDL_Extensions.h"
#include <boost/assign/std/vector.hpp> #include <boost/assign/std/vector.hpp>
#include <sstream> #include <sstream>
@ -12,6 +11,8 @@
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/assign/std/vector.hpp> #include <boost/assign/std/vector.hpp>
#include "../CThreadHelper.h" #include "../CThreadHelper.h"
#include "../CGameInfo.h"
#include "../hch/CLodHandler.h"
using namespace boost::assign; using namespace boost::assign;
using namespace CSDL_Ext; using namespace CSDL_Ext;
Graphics * graphics = NULL; Graphics * graphics = NULL;
@ -30,7 +31,7 @@ SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh)
{ {
char * buf = new char[10]; char * buf = new char[10];
SDL_Surface * ret = SDL_DisplayFormat(hInfo); SDL_Surface * ret = SDL_DisplayFormat(hInfo);
blueToPlayersAdv(hInfo,curh->tempOwner,1); blueToPlayersAdv(hInfo,curh->tempOwner);
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
printAt(curh->name,75,15,GEOR13,zwykly,ret); printAt(curh->name,75,15,GEOR13,zwykly,ret);
drawPrimarySkill(curh, ret); drawPrimarySkill(curh, ret);
@ -52,7 +53,7 @@ SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh)
SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh) SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh)
{ {
char * buf = new char[10]; char * buf = new char[10];
blueToPlayersAdv(tInfo,curh->tempOwner,1); blueToPlayersAdv(tInfo,curh->tempOwner);
SDL_Surface * ret = SDL_DisplayFormat(tInfo); SDL_Surface * ret = SDL_DisplayFormat(tInfo);
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
printAt(curh->name,75,15,GEOR13,zwykly,ret); printAt(curh->name,75,15,GEOR13,zwykly,ret);
@ -82,6 +83,35 @@ SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh)
delete[] buf; delete[] buf;
return ret; return ret;
} }
void Graphics::loadPaletteAndColors()
{
std::string pals = CGI->bitmaph->getTextFile("PLAYERS.PAL");
playerColorPalette = new SDL_Color[256];
neutralColor = new SDL_Color;
playerColors = new SDL_Color[PLAYER_LIMIT];
int startPoint = 24; //beginning byte; used to read
for(int i=0; i<256; ++i)
{
SDL_Color col;
col.r = pals[startPoint++];
col.g = pals[startPoint++];
col.b = pals[startPoint++];
col.unused = pals[startPoint++];
playerColorPalette[i] = col;
}
//colors initialization
int3 kolory[] = {int3(0xff,0,0),int3(0x31,0x52,0xff),int3(0x9c,0x73,0x52),int3(0x42,0x94,0x29),
int3(0xff,0x84,0x0),int3(0x8c,0x29,0xa5),int3(0x09,0x9c,0xa5),int3(0xc6,0x7b,0x8c)};
for(int i=0;i<8;i++)
{
playerColors[i].r = kolory[i].x;
playerColors[i].g = kolory[i].y;
playerColors[i].b = kolory[i].z;
playerColors[i].unused = 0;
}
neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84;//gray
}
Graphics::Graphics() Graphics::Graphics()
{ {
slotsPos.push_back(std::pair<int,int>(44,82)); slotsPos.push_back(std::pair<int,int>(44,82));
@ -95,6 +125,7 @@ Graphics::Graphics()
CDefHandler *smi, *smi2; CDefHandler *smi, *smi2;
std::vector<Task> tasks; //preparing list of graphics to load std::vector<Task> tasks; //preparing list of graphics to load
tasks += boost::bind(&Graphics::loadPaletteAndColors,this);
tasks += boost::bind(&Graphics::loadHeroFlags,this); tasks += boost::bind(&Graphics::loadHeroFlags,this);
tasks += boost::bind(&Graphics::loadHeroPortraits,this); tasks += boost::bind(&Graphics::loadHeroPortraits,this);
tasks += GET_SURFACE(hInfo,"HEROQVBK.bmp"); tasks += GET_SURFACE(hInfo,"HEROQVBK.bmp");
@ -340,3 +371,79 @@ SDL_Surface * Graphics::getPic(int ID, bool fort, bool builded)
return smallIcons->ourImages[pom].bitmap; return smallIcons->ourImages[pom].bitmap;
} }
} }
void Graphics::blueToPlayersAdv(SDL_Surface * sur, int player)
{
if(player==1) //it is actually blue...
return;
if(sur->format->BitsPerPixel == 8)
{
for(int i=0; i<32; ++i)
{
sur->format->palette->colors[224+i] = playerColorPalette[32*player+i];
}
}
else if(sur->format->BitsPerPixel == 24) //should never happen in general
{
for(int y=0; y<sur->h; ++y)
{
for(int x=0; x<sur->w; ++x)
{
Uint8* cp = (Uint8*)sur->pixels + y*sur->pitch + x*3;
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
{
if(cp[2]>cp[1] && cp[2]>cp[0])
{
std::vector<long long int> sort1;
sort1.push_back(cp[0]);
sort1.push_back(cp[1]);
sort1.push_back(cp[2]);
std::vector< std::pair<long long int, Uint8*> > sort2;
sort2.push_back(std::make_pair(graphics->playerColors[player].r, &(cp[0])));
sort2.push_back(std::make_pair(graphics->playerColors[player].g, &(cp[1])));
sort2.push_back(std::make_pair(graphics->playerColors[player].b, &(cp[2])));
std::sort(sort1.begin(), sort1.end());
if(sort2[0].first>sort2[1].first)
std::swap(sort2[0], sort2[1]);
if(sort2[1].first>sort2[2].first)
std::swap(sort2[1], sort2[2]);
if(sort2[0].first>sort2[1].first)
std::swap(sort2[0], sort2[1]);
for(int hh=0; hh<3; ++hh)
{
(*sort2[hh].second) = (sort1[hh] + sort2[hh].first)/2.2;
}
}
}
else
{
if(
(/*(mode==0) && (cp[0]>cp[1]) && (cp[0]>cp[2])) ||
((mode==1) &&*/ (cp[2]<45) && (cp[0]>80) && (cp[1]<70) && ((cp[0]-cp[1])>40))
)
{
std::vector<long long int> sort1;
sort1.push_back(cp[2]);
sort1.push_back(cp[1]);
sort1.push_back(cp[0]);
std::vector< std::pair<long long int, Uint8*> > sort2;
sort2.push_back(std::make_pair(graphics->playerColors[player].r, &(cp[2])));
sort2.push_back(std::make_pair(graphics->playerColors[player].g, &(cp[1])));
sort2.push_back(std::make_pair(graphics->playerColors[player].b, &(cp[0])));
std::sort(sort1.begin(), sort1.end());
if(sort2[0].first>sort2[1].first)
std::swap(sort2[0], sort2[1]);
if(sort2[1].first>sort2[2].first)
std::swap(sort2[1], sort2[2]);
if(sort2[0].first>sort2[1].first)
std::swap(sort2[0], sort2[1]);
for(int hh=0; hh<3; ++hh)
{
(*sort2[hh].second) = (sort1[hh]*0.8 + sort2[hh].first)/2;
}
}
}
}
}
}
}

View File

@ -41,6 +41,7 @@
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="G:\vcmt\repa\include" AdditionalIncludeDirectories="G:\vcmt\repa\include"
GeneratePreprocessedFile="0"
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="3" RuntimeLibrary="3"
@ -304,10 +305,6 @@
RelativePath="..\CGameInterface.cpp" RelativePath="..\CGameInterface.cpp"
> >
</File> </File>
<File
RelativePath="..\CGameState.cpp"
>
</File>
<File <File
RelativePath="..\hch\CGeneralTextHandler.cpp" RelativePath="..\hch\CGeneralTextHandler.cpp"
> >
@ -384,10 +381,6 @@
RelativePath="..\SDL_framerate.cpp" RelativePath="..\SDL_framerate.cpp"
> >
</File> </File>
<File
RelativePath="..\SDL_rotozoom.cpp"
>
</File>
<Filter <Filter
Name="lua" Name="lua"
> >
@ -598,10 +591,6 @@
RelativePath="..\CGameInterface.h" RelativePath="..\CGameInterface.h"
> >
</File> </File>
<File
RelativePath="..\CGameState.h"
>
</File>
<File <File
RelativePath="..\hch\CGeneralTextHandler.h" RelativePath="..\hch\CGeneralTextHandler.h"
> >
@ -694,10 +683,6 @@
RelativePath="..\SDL_framerate.h" RelativePath="..\SDL_framerate.h"
> >
</File> </File>
<File
RelativePath="..\SDL_rotozoom.h"
>
</File>
<File <File
RelativePath="..\StartInfo.h" RelativePath="..\StartInfo.h"
> >

View File

@ -41,6 +41,8 @@ extern CGameInfo* CGI;
#define LOGE(x) ; #define LOGE(x) ;
#endif #endif
#define NAME_VER ("VCMI \"Altanatse\" 0.7")
const int F_NUMBER = 9; //factions (town types) quantity const int F_NUMBER = 9; //factions (town types) quantity
const int PLAYER_LIMIT = 8; //player limit per map const int PLAYER_LIMIT = 8; //player limit per map
const int HEROES_PER_TYPE=8; //amount of heroes of each type const int HEROES_PER_TYPE=8; //amount of heroes of each type

View File

@ -4,6 +4,7 @@
#include "../CGameInfo.h" #include "../CGameInfo.h"
#include "CLodHandler.h" #include "CLodHandler.h"
#include <sstream> #include <sstream>
#include "../lib/VCMI_Lib.h"
extern CLodHandler * bitmaph; extern CLodHandler * bitmaph;
bool CGDefInfo::isVisitable() bool CGDefInfo::isVisitable()
{ {
@ -20,6 +21,7 @@ CGDefInfo::CGDefInfo()
} }
void CDefObjInfoHandler::load() void CDefObjInfoHandler::load()
{ {
VLC->dobjinfo = this;
nodrze<int> ideki; nodrze<int> ideki;
std::istringstream inp(bitmaph->getTextFile("ZOBJCTS.TXT")); std::istringstream inp(bitmaph->getTextFile("ZOBJCTS.TXT"));
int objNumber; int objNumber;
@ -58,8 +60,8 @@ void CDefObjInfoHandler::load()
} }
} }
for(int yy=0; yy<2; ++yy) for(int yy=0; yy<2; ++yy) //first - on which types of terrain object can be placed;
inp>>dump; inp>>dump; //second -in which terrains' menus object in the editor will be available (?)
inp>>nobj->id; inp>>nobj->id;
inp>>nobj->subid; inp>>nobj->subid;
inp>>nobj->type; inp>>nobj->type;

View File

@ -3,6 +3,7 @@
#include "CHeroHandler.h" #include "CHeroHandler.h"
#include <sstream> #include <sstream>
#include "CLodHandler.h" #include "CLodHandler.h"
#include "../lib/VCMI_Lib.h"
extern CLodHandler * bitmaph; extern CLodHandler * bitmaph;
void loadToIt(std::string &dest, std::string &src, int &iter, int mode); void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
CHeroHandler::~CHeroHandler() CHeroHandler::~CHeroHandler()
@ -20,6 +21,7 @@ void CHeroHandler::loadPortraits()
} }
void CHeroHandler::loadHeroes() void CHeroHandler::loadHeroes()
{ {
VLC->heroh = this;
int ID=0; int ID=0;
std::string buf = bitmaph->getTextFile("HOTRAITS.TXT"); std::string buf = bitmaph->getTextFile("HOTRAITS.TXT");
int it=0; int it=0;

View File

@ -13,6 +13,7 @@ DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mod
extern CLodHandler * bitmaph; extern CLodHandler * bitmaph;
void CObjectHandler::loadObjects() void CObjectHandler::loadObjects()
{ {
VLC->objh = this;
int ID=0; int ID=0;
std::string buf = bitmaph->getTextFile("OBJNAMES.TXT"); std::string buf = bitmaph->getTextFile("OBJNAMES.TXT");
int it=0; int it=0;

View File

@ -1,4 +1,4 @@
#include "../stdafx.h" #include "../stdafx.h"
#include "CSpellHandler.h" #include "CSpellHandler.h"
#include "../CGameInfo.h" #include "../CGameInfo.h"
#include "CLodHandler.h" #include "CLodHandler.h"

View File

@ -3,10 +3,13 @@
#include "CTownHandler.h" #include "CTownHandler.h"
#include "CLodHandler.h" #include "CLodHandler.h"
#include <sstream> #include <sstream>
#include "../lib/VCMI_Lib.h"
extern CLodHandler * bitmaph; extern CLodHandler * bitmaph;
void loadToIt(std::string &dest, std::string &src, int &iter, int mode); void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
CTownHandler::CTownHandler() CTownHandler::CTownHandler()
{} {
VLC->townh = this;
}
CTownHandler::~CTownHandler() CTownHandler::~CTownHandler()
{} {}
void CTownHandler::loadNames() void CTownHandler::loadNames()

View File

@ -3,18 +3,18 @@
//class CMapHandler; //class CMapHandler;
class CArtHandler; class CArtHandler;
//class CHeroHandler; class CHeroHandler;
class CCreatureHandler; class CCreatureHandler;
//class CAbilityHandler; //class CAbilityHandler;
//class CSpellHandler; //class CSpellHandler;
//class CAmbarCendamo; //class CAmbarCendamo;
//class CPreGameTextHandler; //class CPreGameTextHandler;
//class CBuildingHandler; //class CBuildingHandler;
//class CObjectHandler; class CObjectHandler;
//class CMusicHandler; //class CMusicHandler;
//class CSemiLodHandler; //class CSemiLodHandler;
class CDefObjInfoHandler; class CDefObjInfoHandler;
//class CTownHandler; class CTownHandler;
//class CGeneralTextHandler; //class CGeneralTextHandler;
//class CConsoleHandler; //class CConsoleHandler;
//class CPathfinder; //class CPathfinder;
@ -31,18 +31,18 @@ class LibClasses
public: public:
//CGameState * state; //CGameState * state;
CArtHandler * arth; CArtHandler * arth;
//CHeroHandler * heroh; CHeroHandler * heroh;
CCreatureHandler * creh; CCreatureHandler * creh;
//CAbilityHandler * abilh; //CAbilityHandler * abilh;
//CSpellHandler * spellh; //CSpellHandler * spellh;
//CMapHandler * mh; //CMapHandler * mh;
//CPreGameTextHandler * preth; //CPreGameTextHandler * preth;
//CBuildingHandler * buildh; //CBuildingHandler * buildh;
//CObjectHandler * objh; CObjectHandler * objh;
//CMusicHandler * mush; //CMusicHandler * mush;
//CSemiLodHandler * sspriteh; //CSemiLodHandler * sspriteh;
CDefObjInfoHandler * dobjinfo; CDefObjInfoHandler * dobjinfo;
//CTownHandler * townh; CTownHandler * townh;
//CGeneralTextHandler * generaltexth; //CGeneralTextHandler * generaltexth;
//CConsoleHandler * consoleh; //CConsoleHandler * consoleh;
//CPathfinder * pathf; //CPathfinder * pathf;

View File

@ -326,8 +326,6 @@
<Files> <Files>
<Filter <Filter
Name="Source Files" Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
> >
<File <File
RelativePath="..\hch\CAmbarCendamo.cpp" RelativePath="..\hch\CAmbarCendamo.cpp"
@ -349,6 +347,10 @@
RelativePath="..\hch\CDefObjInfoHandler.cpp" RelativePath="..\hch\CDefObjInfoHandler.cpp"
> >
</File> </File>
<File
RelativePath="..\CGameState.cpp"
>
</File>
<File <File
RelativePath="..\hch\CHeroHandler.cpp" RelativePath="..\hch\CHeroHandler.cpp"
> >
@ -403,6 +405,10 @@
RelativePath="..\hch\CDefObjInfoHandler.h" RelativePath="..\hch\CDefObjInfoHandler.h"
> >
</File> </File>
<File
RelativePath="..\CGameState.h"
>
</File>
<File <File
RelativePath="..\hch\CHeroHandler.h" RelativePath="..\hch\CHeroHandler.h"
> >

14
map.cpp
View File

@ -947,7 +947,6 @@ Mapa::Mapa(unsigned char * bufor)
//////READING DEF INFO/////// //////READING DEF INFO///////
int defAmount = readNormalNr(bufor,i); i+=4; int defAmount = readNormalNr(bufor,i); i+=4;
defy.reserve(defAmount); defy.reserve(defAmount);
for (int idd = 0 ; idd<defAmount; idd++) // reading defs for (int idd = 0 ; idd<defAmount; idd++) // reading defs
{ {
CGDefInfo * vinya = new CGDefInfo(); // info about new def CGDefInfo * vinya = new CGDefInfo(); // info about new def
@ -1233,9 +1232,6 @@ Mapa::Mapa(unsigned char * bufor)
nhi->movement = -1; nhi->movement = -1;
if(nhi->ID==34) if(nhi->ID==34)
heroes.push_back(nhi); heroes.push_back(nhi);
//else
// CGI->objh->objInstances.push_back(nhi);
break; break;
} }
case CREATURES_DEF: case CREATURES_DEF:
@ -1860,6 +1856,7 @@ Mapa::Mapa(unsigned char * bufor)
nt->builded = 0; nt->builded = 0;
nt->destroyed = 0; nt->destroyed = 0;
nt->garrisonHero = NULL; nt->garrisonHero = NULL;
if(nt->ID=98)
towns.push_back(nt); towns.push_back(nt);
break; break;
} }
@ -2291,3 +2288,12 @@ borderguardend:
//map readed, bufor no longer needed //map readed, bufor no longer needed
delete[] bufor; bufor=NULL; delete[] bufor; bufor=NULL;
} }
CGHeroInstance * Mapa::getHero(int ID, int mode)
{
if (mode != 0)
throw new std::exception("gs->getHero: This mode is not supported!");
for(int i=0; i<heroes.size();i++)
if(heroes[i]->subID == ID)
return heroes[i];
return NULL;
}

71
map.h
View File

@ -4,6 +4,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
#include <set>
#include "global.h" #include "global.h"
class CGDefInfo; class CGDefInfo;
class CGObjectInstance; class CGObjectInstance;
@ -363,40 +364,6 @@ public:
int firstOccurence; int firstOccurence;
int nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time; int nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time;
}; };
struct DLL_EXPORT Mapa
{
Eformat version; // version of map Eformat
int twoLevel; // if map has underground level
int difficulty; // 0 easy - 4 impossible
int levelLimit;
bool areAnyPLayers; // if there are any playable players on map
std::string name; //name of map
std::string description; //and description
int height, width;
TerrainTile** terrain;
TerrainTile** undergroungTerrain; // used only if there is underground level
std::vector<Rumor> rumors;
std::vector<DisposedHero> disposedHeroes;
std::vector<CGHeroInstance*> predefinedHeroes;
std::vector<CGDefInfo *> defy; // list of .def files
PlayerInfo players[8]; // info about players
std::vector<int> teams; // teams[i] = team of player no i
LossCondition lossCondition;
EvictoryConditions victoryCondition; //victory conditions
CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
int howManyTeams;
std::vector<bool> allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed
std::vector<bool> allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed
std::vector<bool> allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed
std::vector<bool> allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed
std::vector<CMapEvent> events;
std::vector<CGObjectInstance*> objects;
std::vector<CGHeroInstance*> heroes;
std::vector<CGTownInstance*> towns;
Mapa(unsigned char * bufor); //creates map from decompressed .h3m data
};
class DLL_EXPORT CMapHeader class DLL_EXPORT CMapHeader
{ {
public: public:
@ -478,4 +445,40 @@ public:
}; };
mapSorter(ESortBy es):sortBy(es){}; mapSorter(ESortBy es):sortBy(es){};
}; };
struct DLL_EXPORT Mapa
{
Eformat version; // version of map Eformat
int twoLevel; // if map has underground level
int difficulty; // 0 easy - 4 impossible
int levelLimit;
bool areAnyPLayers; // if there are any playable players on map
std::string name; //name of map
std::string description; //and description
int height, width;
TerrainTile** terrain;
TerrainTile** undergroungTerrain; // used only if there is underground level
std::vector<Rumor> rumors;
std::vector<DisposedHero> disposedHeroes;
std::vector<CGHeroInstance*> predefinedHeroes;
std::vector<CGDefInfo *> defy; // list of .def files with definitions from .h3m (may be custom)
std::set<CGDefInfo *> defs; // other defInfos - for randomized objects, objects added or modified by script
PlayerInfo players[8]; // info about players
std::vector<int> teams; // teams[i] = team of player no i
LossCondition lossCondition;
EvictoryConditions victoryCondition; //victory conditions
CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
int howManyTeams;
std::vector<bool> allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed
std::vector<bool> allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed
std::vector<bool> allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed
std::vector<bool> allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed
std::vector<CMapEvent> events;
std::vector<CGObjectInstance*> objects;
std::vector<CGHeroInstance*> heroes;
std::vector<CGTownInstance*> towns;
Mapa(unsigned char * bufor); //creates map from decompressed .h3m data
CGHeroInstance * getHero(int ID, int mode=0);
};
#endif //MAPD_H #endif //MAPD_H

View File

@ -1,9 +1,8 @@
#include "stdafx.h" #include "stdafx.h"
#include "mapHandler.h" #include "mapHandler.h"
#include "SDL_rotozoom.h"
#include "SDL_Extensions.h" #include "SDL_Extensions.h"
#include "CGameInfo.h" #include "CGameInfo.h"
#include "stdlib.h" #include <cstdlib>
#include "hch\CLodHandler.h" #include "hch\CLodHandler.h"
#include "hch\CDefObjInfoHandler.h" #include "hch\CDefObjInfoHandler.h"
#include <algorithm> #include <algorithm>
@ -11,7 +10,6 @@
#include "CLua.h" #include "CLua.h"
#include "hch\CHeroHandler.h" #include "hch\CHeroHandler.h"
#include "hch\CTownHandler.h" #include "hch\CTownHandler.h"
#include "hch\CArtHandler.h"
#include "client\Graphics.h" #include "client\Graphics.h"
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
@ -87,262 +85,10 @@ void alphaTransformDef(CGDefInfo * defInfo)
for(int yy=0;yy<defInfo->handler->ourImages.size();yy++) for(int yy=0;yy<defInfo->handler->ourImages.size();yy++)
{ {
defInfo->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(defInfo->handler->ourImages[yy].bitmap); defInfo->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(defInfo->handler->ourImages[yy].bitmap);
//SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(defInfo->handler->ourImages[yy].bitmap, alphaTransSurf);
//SDL_FreeSurface(defInfo->handler->ourImages[yy].bitmap);
//defInfo->handler->ourImages[yy].bitmap = bufs;
defInfo->handler->alphaTransformed = true; defInfo->handler->alphaTransformed = true;
} }
SDL_FreeSurface(alphaTransSurf); SDL_FreeSurface(alphaTransSurf);
} }
int CMapHandler::pickHero(int owner)
{
int h;
if(usedHeroes.find(h = CGI->scenarioOps.getIthPlayersSettings(owner).hero)==usedHeroes.end() && h>=0) //we haven't used selected hero
{
usedHeroes.insert(h);
return h;
}
int f = CGI->scenarioOps.getIthPlayersSettings(owner).castle;
int i=0;
do //try to find free hero of our faction
{
i++;
h = CGI->scenarioOps.getIthPlayersSettings(owner).castle*HEROES_PER_TYPE*2+(rand()%(HEROES_PER_TYPE*2));//cgi->scenarioOps.playerInfos[pru].hero = cgi->
} while((usedHeroes.find(h)!=usedHeroes.end()) && i<175);
if(i>174) //probably no free heroes - there's no point in further search, we'll take first free
{
for(int j=0; j<HEROES_PER_TYPE * 2 * F_NUMBER; j++)
if(usedHeroes.find(j)==usedHeroes.end())
h=j;
}
usedHeroes.insert(h);
return h;
}
std::pair<int,int> CMapHandler::pickObject(CGObjectInstance *obj)
{
switch(obj->ID)
{
case 65: //random artifact
return std::pair<int,int>(5,(rand()%136)+7); //tylko sensowny zakres - na poczatku sa katapulty itp, na koncu specjalne i blanki
case 66: //random treasure artifact
return std::pair<int,int>(5,CGI->arth->treasures[rand()%CGI->arth->treasures.size()]->id);
case 67: //random minor artifact
return std::pair<int,int>(5,CGI->arth->minors[rand()%CGI->arth->minors.size()]->id);
case 68: //random major artifact
return std::pair<int,int>(5,CGI->arth->majors[rand()%CGI->arth->majors.size()]->id);
case 69: //random relic artifact
return std::pair<int,int>(5,CGI->arth->relics[rand()%CGI->arth->relics.size()]->id);
case 70: //random hero
{
return std::pair<int,int>(34,pickHero(obj->tempOwner));
}
case 71: //random monster
return std::pair<int,int>(54,rand()%(CGI->creh->creatures.size()));
case 72: //random monster lvl1
return std::pair<int,int>(54,CGI->creh->levelCreatures[1][rand()%CGI->creh->levelCreatures[1].size()]->idNumber);
case 73: //random monster lvl2
return std::pair<int,int>(54,CGI->creh->levelCreatures[2][rand()%CGI->creh->levelCreatures[2].size()]->idNumber);
case 74: //random monster lvl3
return std::pair<int,int>(54,CGI->creh->levelCreatures[3][rand()%CGI->creh->levelCreatures[3].size()]->idNumber);
case 75: //random monster lvl4
return std::pair<int,int>(54,CGI->creh->levelCreatures[4][rand()%CGI->creh->levelCreatures[4].size()]->idNumber);
case 76: //random resource
return std::pair<int,int>(79,rand()%7); //now it's OH3 style, use %8 for mithril
case 77: //random town
{
int align = ((CGTownInstance*)obj)->alignment,
f;
if(align>PLAYER_LIMIT-1)//same as owner / random
{
if(obj->tempOwner > PLAYER_LIMIT-1)
f = -1; //random
else
f = CGI->scenarioOps.getIthPlayersSettings(obj->tempOwner).castle;
}
else
{
f = CGI->scenarioOps.getIthPlayersSettings(align).castle;
}
if(f<0) f = rand()%CGI->townh->towns.size();
return std::pair<int,int>(98,f);
}
case 162: //random monster lvl5
return std::pair<int,int>(54,CGI->creh->levelCreatures[5][rand()%CGI->creh->levelCreatures[5].size()]->idNumber);
case 163: //random monster lvl6
return std::pair<int,int>(54,CGI->creh->levelCreatures[6][rand()%CGI->creh->levelCreatures[6].size()]->idNumber);
case 164: //random monster lvl7
return std::pair<int,int>(54,CGI->creh->levelCreatures[7][rand()%CGI->creh->levelCreatures[7].size()]->idNumber);
case 216: //random dwelling
{
int faction = rand()%F_NUMBER;
CCreGen2ObjInfo* info =(CCreGen2ObjInfo*)obj->info;
if (info->asCastle)
{
for(int i=0;i<map->objects.size();i++)
{
if(map->objects[i]->ID==77 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
randomizeObject(map->objects[i]); //we have to randomize the castle first
faction = map->objects[i]->subID;
break;
}
else if(map->objects[i]->ID==98 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
faction = map->objects[i]->subID;
break;
}
}
}
else
{
while((!(info->castles[0]&(1<<faction))))
{
if((faction>7) && (info->castles[1]&(1<<(faction-8))))
break;
faction = rand()%F_NUMBER;
}
}
int level = ((info->maxLevel-info->minLevel) ? (rand()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel));
int cid = CGI->townh->towns[faction].basicCreatures[level];
for(int i=0;i<CGI->objh->cregens.size();i++)
if(CGI->objh->cregens[i]==cid)
return std::pair<int,int>(17,i);
std::cout << "Cannot find a dwelling for creature "<<cid <<std::endl;
return std::pair<int,int>(17,0);
}
case 217:
{
int faction = rand()%F_NUMBER;
CCreGenObjInfo* info =(CCreGenObjInfo*)obj->info;
if (info->asCastle)
{
for(int i=0;i<map->objects.size();i++)
{
if(map->objects[i]->ID==77 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
randomizeObject(map->objects[i]); //we have to randomize the castle first
faction = map->objects[i]->subID;
break;
}
else if(map->objects[i]->ID==98 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
faction = map->objects[i]->subID;
break;
}
}
}
else
{
while((!(info->castles[0]&(1<<faction))))
{
if((faction>7) && (info->castles[1]&(1<<(faction-8))))
break;
faction = rand()%F_NUMBER;
}
}
int cid = CGI->townh->towns[faction].basicCreatures[obj->subID];
for(int i=0;i<CGI->objh->cregens.size();i++)
if(CGI->objh->cregens[i]==cid)
return std::pair<int,int>(17,i);
std::cout << "Cannot find a dwelling for creature "<<cid <<std::endl;
return std::pair<int,int>(17,0);
}
case 218:
{
CCreGen3ObjInfo* info =(CCreGen3ObjInfo*)obj->info;
int level = ((info->maxLevel-info->minLevel) ? (rand()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel));
int cid = CGI->townh->towns[obj->subID].basicCreatures[level];
for(int i=0;i<CGI->objh->cregens.size();i++)
if(CGI->objh->cregens[i]==cid)
return std::pair<int,int>(17,i);
std::cout << "Cannot find a dwelling for creature "<<cid <<std::endl;
return std::pair<int,int>(17,0);
}
}
return std::pair<int,int>(-1,-1);
}
void CMapHandler::randomizeObject(CGObjectInstance *cur)
{
std::pair<int,int> ran = pickObject(cur);
if(ran.first<0 || ran.second<0) //this is not a random object, or we couldn't find anything
{
if(cur->ID==98) //town - set def
{
CGTownInstance *t = dynamic_cast<CGTownInstance*>(cur);
if(t->hasCapitol())
t->defInfo = capitols[t->subID];
else if(t->hasFort())
t->defInfo = CGI->dobjinfo->castles[t->subID];
else
t->defInfo = villages[t->subID];
if(!t->defInfo->handler)
{
t->defInfo->handler = CDefHandler::giveDef(t->defInfo->name);
t->defInfo->width = t->defInfo->handler->ourImages[0].bitmap->w/32;
t->defInfo->height = t->defInfo->handler->ourImages[0].bitmap->h/32;
alphaTransformDef(t->defInfo);
}
}
return;
}
else if(ran.first==34)//special code for hero
{
CGHeroInstance *h = dynamic_cast<CGHeroInstance *>(cur);
if(!h) {std::cout<<"Wrong random hero at "<<cur->pos<<std::endl; return;}
cur->ID = ran.first;
cur->subID = ran.second;
h->type = CGI->heroh->heroes[ran.second];
map->heroes.push_back(h);
map->objects.erase(std::find(map->objects.begin(),map->objects.end(),h));
return; //TODO: maybe we should do something with definfo?
}
else if(ran.first==98)//special code for town
{
CGTownInstance *t = dynamic_cast<CGTownInstance*>(cur);
if(!t) {std::cout<<"Wrong random town at "<<cur->pos<<std::endl; return;}
cur->ID = ran.first;
cur->subID = ran.second;
t->town = &CGI->townh->towns[ran.second];
if(t->hasCapitol())
t->defInfo = capitols[t->subID];
else if(t->hasFort())
t->defInfo = CGI->dobjinfo->castles[t->subID];
else
t->defInfo = villages[t->subID];
if(!t->defInfo->handler)
{
t->defInfo->handler = CDefHandler::giveDef(t->defInfo->name);
t->defInfo->width = t->defInfo->handler->ourImages[0].bitmap->w/32;
t->defInfo->height = t->defInfo->handler->ourImages[0].bitmap->h/32;
alphaTransformDef(t->defInfo);
}
//CGI->townh->townInstances.push_back(t);
return;
}
//we have to replace normal random object
cur->ID = ran.first;
cur->subID = ran.second;
cur->defInfo = CGI->dobjinfo->gobjs[ran.first][ran.second];
if(!cur->defInfo){std::cout<<"Missing def declaration for "<<cur->ID<<" "<<cur->subID<<std::endl;return;}
if(!cur->defInfo->handler) //if we have to load def
{
cur->defInfo->handler = CDefHandler::giveDef(cur->defInfo->name);
cur->defInfo->width = cur->defInfo->handler->ourImages[0].bitmap->w/32;
cur->defInfo->height = cur->defInfo->handler->ourImages[0].bitmap->h/32;
alphaTransformDef(cur->defInfo);
}
}
void CMapHandler::randomizeObjects()
{
CGObjectInstance * cur;
for(int no=0; no<map->objects.size(); ++no)
{
randomizeObject(map->objects[no]);
if(map->objects[no]->ID==26)
map->objects[no]->defInfo->handler=NULL;
}
}
void CMapHandler::prepareFOWDefs() void CMapHandler::prepareFOWDefs()
{ {
fullHide = CDefHandler::giveDef("TSHRC.DEF"); fullHide = CDefHandler::giveDef("TSHRC.DEF");
@ -399,43 +145,35 @@ void CMapHandler::prepareFOWDefs()
// visibility[gg][jj] = true; // visibility[gg][jj] = true;
//} //}
visibility.resize(CGI->mh->map->width, Woff); //visibility.resize(CGI->mh->map->width, Woff);
for (int i=0-Woff;i<visibility.size()-Woff;i++) //for (int i=0-Woff;i<visibility.size()-Woff;i++)
{ //{
visibility[i].resize(CGI->mh->map->height,Hoff); // visibility[i].resize(CGI->mh->map->height,Hoff);
} //}
for (int i=0-Woff; i<visibility.size()-Woff; ++i) //for (int i=0-Woff; i<visibility.size()-Woff; ++i)
{ //{
for (int j=0-Hoff; j<CGI->mh->map->height+Hoff; ++j) // for (int j=0-Hoff; j<CGI->mh->map->height+Hoff; ++j)
{ // {
visibility[i][j].resize(CGI->mh->map->twoLevel+1,0); // visibility[i][j].resize(CGI->mh->map->twoLevel+1,0);
for(int k=0; k<CGI->mh->map->twoLevel+1; ++k) // for(int k=0; k<CGI->mh->map->twoLevel+1; ++k)
visibility[i][j][k]=true; // visibility[i][j][k]=true;
} // }
} //}
hideBitmap.resize(CGI->mh->map->width, Woff); hideBitmap.resize(CGI->mh->map->width);
for (int i=0-Woff;i<visibility.size()-Woff;i++) for (int i=0;i<hideBitmap.size();i++)
{ {
hideBitmap[i].resize(CGI->mh->map->height,Hoff); hideBitmap[i].resize(CGI->mh->map->height);
} }
for (int i=0-Woff; i<hideBitmap.size()-Woff; ++i) for (int i=0; i<hideBitmap.size(); ++i)
{ {
for (int j=0-Hoff; j<CGI->mh->map->height+Hoff; ++j) for (int j=0; j<CGI->mh->map->height; ++j)
{ {
hideBitmap[i][j].resize(CGI->mh->map->twoLevel+1,0); hideBitmap[i][j].resize(CGI->mh->map->twoLevel+1);
for(int k=0; k<CGI->mh->map->twoLevel+1; ++k) for(int k=0; k<CGI->mh->map->twoLevel+1; ++k)
hideBitmap[i][j][k] = rand()%fullHide->ourImages.size(); hideBitmap[i][j][k] = rand()%fullHide->ourImages.size();
} }
} }
//visibility[6][7][1] = false;
//visibility[7][7][1] = false;
//visibility[6][8][1] = false;
//visibility[6][6][1] = false;
//visibility[5][8][1] = false;
//visibility[7][6][1] = false;
//visibility[6][9][1] = false;
} }
void CMapHandler::roadsRiverTerrainInit() void CMapHandler::roadsRiverTerrainInit()
@ -464,9 +202,6 @@ void CMapHandler::roadsRiverTerrainInit()
} }
} }
//roadBitmaps = new SDL_Surface** [map->width+2*Woff];
//for (int ii=0;ii<map->width+2*Woff;ii++)
// roadBitmaps[ii] = new SDL_Surface*[map->height+2*Hoff]; // allocate memory
sizes.x = CGI->mh->map->width; sizes.x = CGI->mh->map->width;
sizes.y = CGI->mh->map->height; sizes.y = CGI->mh->map->height;
sizes.z = CGI->mh->map->twoLevel+1; sizes.z = CGI->mh->map->twoLevel+1;
@ -615,10 +350,6 @@ void CMapHandler::roadsRiverTerrainInit()
} }
void CMapHandler::borderAndTerrainBitmapInit() void CMapHandler::borderAndTerrainBitmapInit()
{ {
//terrainBitmap = new SDL_Surface **[map->width+2*Woff];
//for (int ii=0;ii<map->width+2*Woff;ii++)
// terrainBitmap[ii] = new SDL_Surface*[map->height+2*Hoff]; // allocate memory
CDefHandler * bord = CDefHandler::giveDef("EDG.DEF"); CDefHandler * bord = CDefHandler::giveDef("EDG.DEF");
bord->notFreeImgs = true; bord->notFreeImgs = true;
for (int i=0-Woff; i<map->width+Woff; i++) //jest po szeroko�ci for (int i=0-Woff; i<map->width+Woff; i++) //jest po szeroko�ci
@ -807,73 +538,59 @@ void CMapHandler::calculateBlockedPos()
} }
} }
} }
void CMapHandler::init() void processDef (CGDefInfo* def)
{ {
timeHandler th; def->handler=CDefHandler::giveDef(def->name);
th.getDif(); def->width = def->handler->ourImages[0].bitmap->w/32;
def->height = def->handler->ourImages[0].bitmap->h/32;
///loading defs from lod CGDefInfo* pom = CGI->dobjinfo->gobjs[def->id][def->subid];
for (int ir=0;ir<map->defy.size();ir++)
{
map->defy[ir]->handler=CDefHandler::giveDef(map->defy[ir]->name);
map->defy[ir]->width = map->defy[ir]->handler->ourImages[0].bitmap->w/32;
map->defy[ir]->height = map->defy[ir]->handler->ourImages[0].bitmap->h/32;
CGDefInfo* pom = CGI->dobjinfo->gobjs[map->defy[ir]->id][map->defy[ir]->subid];
if(pom) if(pom)
{ {
pom->handler=map->defy[ir]->handler; pom->handler = def->handler;
pom->width = pom->handler->ourImages[0].bitmap->w/32; pom->width = pom->handler->ourImages[0].bitmap->w/32;
pom->height = pom->handler->ourImages[0].bitmap->h/32; pom->height = pom->handler->ourImages[0].bitmap->h/32;
} }
else else
std::cout << "Lacking def info for " << map->defy[ir]->id << " " << map->defy[ir]->subid <<" " << map->defy[ir]->name << std::endl; std::cout << "\t\tMinor warning: lacking def info for " << def->id << " " << def->subid <<" " << def->name << std::endl;
} if(!def->handler->alphaTransformed)
for(int vv=0; vv<map->defy.size(); ++vv)
{ {
if(map->defy[vv]->handler->alphaTransformed) for(int yy=0; yy<def->handler->ourImages.size(); ++yy)
continue;
for(int yy=0; yy<map->defy[vv]->handler->ourImages.size(); ++yy)
{ {
map->defy[vv]->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map->defy[vv]->handler->ourImages[yy].bitmap); def->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(def->handler->ourImages[yy].bitmap);
map->defy[vv]->handler->alphaTransformed = true; def->handler->alphaTransformed = true;
} }
} }
}
void CMapHandler::init()
{
timeHandler th;
th.getDif();
std::for_each(map->defy.begin(),map->defy.end(),processDef); //load h3m defs
std::for_each(map->defs.begin(),map->defs.end(),processDef); //and non-h3m defs
THC std::cout<<"\tUnpacking and handling defs: "<<th.getDif()<<std::endl; THC std::cout<<"\tUnpacking and handling defs: "<<th.getDif()<<std::endl;
//loading castles' defs //loading castles' defs
std::ifstream ifs("config/townsDefs.txt"); //std::ifstream ifs("config/townsDefs.txt");
int ccc; //int ccc;
ifs>>ccc; //ifs>>ccc;
for(int i=0;i<ccc*2;i++) //for(int i=0;i<ccc*2;i++)
{ //{
CGDefInfo * n = new CGDefInfo(*CGI->dobjinfo->castles[i%ccc]); // //CGDefInfo * n = new CGDefInfo(*CGI->dobjinfo->castles[i%ccc]);
ifs >> n->name; // ifs >> n->name;
if (!(n->handler = CDefHandler::giveDef(n->name))) // if (!(n->handler = CDefHandler::giveDef(n->name)))
std::cout << "Cannot open "<<n->name<<std::endl; // std::cout << "Cannot open "<<n->name<<std::endl;
else // else
{ // {
n->width = n->handler->ourImages[0].bitmap->w/32; // n->width = n->handler->ourImages[0].bitmap->w/32;
n->height = n->handler->ourImages[0].bitmap->h/32; // n->height = n->handler->ourImages[0].bitmap->h/32;
} // }
if(i<ccc) // if(i<ccc)
villages[i]=n; // villages[i]=n;
else // else
capitols[i%ccc]=n; // capitols[i%ccc]=n;
alphaTransformDef(n); // alphaTransformDef(n);
} //}
for(int i=0;i<CGI->scenarioOps.playerInfos.size();i++)
{
if(CGI->scenarioOps.playerInfos[i].castle==-1)
{
int f;
do
{
f = rand()%F_NUMBER;
}while(!(map->players[CGI->scenarioOps.playerInfos[i].color].allowedFactions & 1<<f));
CGI->scenarioOps.playerInfos[i].castle = f;
}
}
for(int i=0;i<PLAYER_LIMIT;i++) for(int i=0;i<PLAYER_LIMIT;i++)
{ {
for(int j=0; j<map->players[i].heroesNames.size();j++) for(int j=0; j<map->players[i].heroesNames.size();j++)
@ -884,15 +601,9 @@ void CMapHandler::init()
std::cout<<"\tLoading town defs, picking random factions and heroes: "<<th.getDif()<<std::endl; std::cout<<"\tLoading town defs, picking random factions and heroes: "<<th.getDif()<<std::endl;
randomizeObjects();//randomizing objects on map
std::cout<<"\tRandomizing objects: "<<th.getDif()<<std::endl;
for(int h=0; h<map->defy.size(); ++h) //initializing loaded def handler's info for(int h=0; h<map->defy.size(); ++h) //initializing loaded def handler's info {
{
//std::string hlp = map->defy[h]->name;
//std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler)); CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler));
}
std::cout<<"\tCollecting loaded def's handlers: "<<th.getDif()<<std::endl; std::cout<<"\tCollecting loaded def's handlers: "<<th.getDif()<<std::endl;
prepareFOWDefs(); prepareFOWDefs();
@ -901,27 +612,25 @@ void CMapHandler::init()
std::cout<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDif()<<std::endl; std::cout<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDif()<<std::endl;
//giving starting hero //giving starting hero
for(int i=0;i<PLAYER_LIMIT;i++) //for(int i=0;i<PLAYER_LIMIT;i++)
{ //{
if((map->players[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==RoE)) // if((map->players[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==RoE))
{ // {
int3 hpos = map->players[i].posOfMainTown; // int3 hpos = map->players[i].posOfMainTown;
hpos.x+=1;// hpos.y+=1; // hpos.x+=1;// hpos.y+=1;
int j; // int j;
for(j=0;j<CGI->scenarioOps.playerInfos.size();j++) // for(j=0;j<CGI->state->scenarioOps->playerInfos.size();j++)
if(CGI->scenarioOps.playerInfos[j].color==i) // if(CGI->state->scenarioOps->playerInfos[j].color==i)
break; // break;
if(j==CGI->scenarioOps.playerInfos.size()) // if(j==CGI->state->scenarioOps->playerInfos.size())
continue; // continue;
int h; //= CGI->scenarioOps.playerInfos[j].hero; // int h=pickHero(i);
//if(h<0) // CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,h,hpos,i);
h=pickHero(i); // nnn->defInfo->handler = graphics->flags1[0];
CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,h,hpos,i); // map->heroes.push_back(nnn);
nnn->defInfo->handler = graphics->flags1[0]; // map->objects.push_back(nnn);
map->heroes.push_back(nnn); // }
map->objects.push_back(nnn); //}
}
}
std::cout<<"\tGiving starting heroes: "<<th.getDif()<<std::endl; std::cout<<"\tGiving starting heroes: "<<th.getDif()<<std::endl;
initObjectRects(); initObjectRects();
@ -954,7 +663,7 @@ void CMapHandler::init()
} }
} }
SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect) SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect)
{ {
if(!otherHeroAnim) if(!otherHeroAnim)
heroAnim = anim; //the same, as it should be heroAnim = anim; //the same, as it should be
@ -1200,250 +909,261 @@ SDL_Surface * CMapHandler::undTerrBitmap(int x, int y)
return ttiles[x+Woff][y+Hoff][0].terbitmap[1]; return ttiles[x+Woff][y+Hoff][0].terbitmap[1];
} }
SDL_Surface * CMapHandler::getVisBitmap(int x, int y, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap, int lvl) SDL_Surface * CMapHandler::getVisBitmap(int x, int y, std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl)
{ {
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) int size = visibilityMap.size()-1; //is tile visible. arrangement: (like num keyboard)
bool d7 = (x>0 && y>0) ? visibilityMap[x-1][y-1][lvl] : 0, //789
d8 = (y>0) ? visibilityMap[x][y-1][lvl] : 0, //456
d9 = (y>0 && x<size) ? visibilityMap[x+1][y-1][lvl] : 0,//123
d4 = (x>0) ? visibilityMap[x-1][y][lvl] : 0,
d5 = visibilityMap[x][y][lvl],
d6 = (x<size) ? visibilityMap[x+1][y][lvl] : 0,
d1 = (x>0 && y<size) ? visibilityMap[x-1][y+1][lvl] : 0,
d2 = (y<size) ? visibilityMap[x][y+1][lvl] : 0,
d3 = (x<size && y<size) ? visibilityMap[x+1][y+1][lvl] : 0;
if(!d2 && !d6 && !d4 && !d8 && !d7 && !d3 && !d9 && !d1)
{ {
return fullHide->ourImages[hideBitmap[x][y][lvl]].bitmap; //fully hidden return fullHide->ourImages[hideBitmap[x][y][lvl]].bitmap; //fully hidden
} }
else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) else if(!d2 && !d6 && !d4 && !d8 && !d7 && d3 && !d9 && !d1)
{ {
return partialHide->ourImages[22].bitmap; //visible right bottom corner return partialHide->ourImages[22].bitmap; //visible right bottom corner
} }
else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) else if(!d2 && !d6 && !d4 && !d8 && !d7 && !d3 && d9 && !d1)
{ {
return partialHide->ourImages[15].bitmap; //visible right top corner return partialHide->ourImages[15].bitmap; //visible right top corner
} }
else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) else if(!d2 && !d6 && !d4 && !d8 && !d7 && !d3 && !d9 && d1)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[22].bitmap); //visible left bottom corner //return CSDL_Ext::rotate01(partialHide->ourImages[22].bitmap); //visible left bottom corner
return partialHide->ourImages[34].bitmap; //visible left bottom corner return partialHide->ourImages[34].bitmap; //visible left bottom corner
} }
else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) else if(!d2 && !d6 && !d4 && !d8 && d7 && !d3 && !d9 && !d1)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[15].bitmap); //visible left top corner //return CSDL_Ext::rotate01(partialHide->ourImages[15].bitmap); //visible left top corner
return partialHide->ourImages[35].bitmap; return partialHide->ourImages[35].bitmap;
} }
else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) else if(!d2 && !d6 && !d4 && d8 && d7 && !d3 && d9 && !d1)
{ {
//return partialHide->ourImages[rand()%2].bitmap; //visible top //return partialHide->ourImages[rand()%2].bitmap; //visible top
return partialHide->ourImages[0].bitmap; //visible top return partialHide->ourImages[0].bitmap; //visible top
} }
else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) else if(d2 && !d6 && !d4 && !d8 && !d7 && d3 && !d9 && d1)
{ {
//return partialHide->ourImages[4+rand()%2].bitmap; //visble bottom //return partialHide->ourImages[4+rand()%2].bitmap; //visble bottom
return partialHide->ourImages[4].bitmap; //visble bottom return partialHide->ourImages[4].bitmap; //visble bottom
} }
else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) else if(!d2 && !d6 && d4 && !d8 && d7 && !d3 && !d9 && d1)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[2+rand()%2].bitmap); //visible left //return CSDL_Ext::rotate01(partialHide->ourImages[2+rand()%2].bitmap); //visible left
//return CSDL_Ext::rotate01(partialHide->ourImages[2].bitmap); //visible left //return CSDL_Ext::rotate01(partialHide->ourImages[2].bitmap); //visible left
return partialHide->ourImages[36].bitmap; return partialHide->ourImages[36].bitmap;
} }
else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) else if(!d2 && d6 && !d4 && !d8 && !d7 && d3 && d9 && !d1)
{ {
//return partialHide->ourImages[2+rand()%2].bitmap; //visible right //return partialHide->ourImages[2+rand()%2].bitmap; //visible right
return partialHide->ourImages[2].bitmap; //visible right return partialHide->ourImages[2].bitmap; //visible right
} }
else if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl]) else if(d2 && d6 && !d4 && !d8 && !d7)
{ {
//return partialHide->ourImages[12+2*(rand()%2)].bitmap; //visible bottom, right - bottom, right; left top corner hidden //return partialHide->ourImages[12+2*(rand()%2)].bitmap; //visible bottom, right - bottom, right; left top corner hidden
return partialHide->ourImages[12].bitmap; //visible bottom, right - bottom, right; left top corner hidden return partialHide->ourImages[12].bitmap; //visible bottom, right - bottom, right; left top corner hidden
} }
else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) else if(!d2 && d6 && !d4 && d8 && !d1)
{ {
return partialHide->ourImages[13].bitmap; //visible right, right - top; left bottom corner hidden return partialHide->ourImages[13].bitmap; //visible right, right - top; left bottom corner hidden
} }
else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y+1][lvl]) else if(!d2 && !d6 && d4 && d8 && !d3)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[13].bitmap); //visible top, top - left, left; right bottom corner hidden //return CSDL_Ext::rotate01(partialHide->ourImages[13].bitmap); //visible top, top - left, left; right bottom corner hidden
return partialHide->ourImages[37].bitmap; return partialHide->ourImages[37].bitmap;
} }
else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y-1][lvl]) else if(d2 && !d6 && d4 && !d8 && !d9)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[12+2*(rand()%2)].bitmap); //visible left, left - bottom, bottom; right top corner hidden //return CSDL_Ext::rotate01(partialHide->ourImages[12+2*(rand()%2)].bitmap); //visible left, left - bottom, bottom; right top corner hidden
//return CSDL_Ext::rotate01(partialHide->ourImages[12].bitmap); //visible left, left - bottom, bottom; right top corner hidden //return CSDL_Ext::rotate01(partialHide->ourImages[12].bitmap); //visible left, left - bottom, bottom; right top corner hidden
return partialHide->ourImages[38].bitmap; return partialHide->ourImages[38].bitmap;
} }
else if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) else if(d2 && d6 && d4 && d8)
{ {
return partialHide->ourImages[10].bitmap; //visible left, right, bottom and top return partialHide->ourImages[10].bitmap; //visible left, right, bottom and top
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && !d8 && !d7 && d3 && d9 && !d1)
{ {
return partialHide->ourImages[16].bitmap; //visible right corners return partialHide->ourImages[16].bitmap; //visible right corners
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && !d8 && d7 && !d3 && d9 && !d1)
{ {
return partialHide->ourImages[18].bitmap; //visible top corners return partialHide->ourImages[18].bitmap; //visible top corners
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && !d8 && d7 && !d3 && !d9 && d1)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[16].bitmap); //visible left corners //return CSDL_Ext::rotate01(partialHide->ourImages[16].bitmap); //visible left corners
return partialHide->ourImages[39].bitmap; return partialHide->ourImages[39].bitmap;
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && !d8 && !d7 && d3 && !d9 && d1)
{ {
//return CSDL_Ext::hFlip(partialHide->ourImages[18].bitmap); //visible bottom corners //return CSDL_Ext::hFlip(partialHide->ourImages[18].bitmap); //visible bottom corners
return partialHide->ourImages[40].bitmap; return partialHide->ourImages[40].bitmap;
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && !d8 && !d7 && !d3 && d9 && d1)
{ {
return partialHide->ourImages[17].bitmap; //visible right - top and bottom - left corners return partialHide->ourImages[17].bitmap; //visible right - top and bottom - left corners
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && !d8 && d7 && d3 && !d9 && !d1)
{ {
//return CSDL_Ext::hFlip(partialHide->ourImages[17].bitmap); //visible top - left and bottom - right corners //return CSDL_Ext::hFlip(partialHide->ourImages[17].bitmap); //visible top - left and bottom - right corners
return partialHide->ourImages[41].bitmap; return partialHide->ourImages[41].bitmap;
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && !d8 && !d7 && d3 && d9 && d1)
{ {
return partialHide->ourImages[19].bitmap; //visible corners without left top return partialHide->ourImages[19].bitmap; //visible corners without left top
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && !d8 && d7 && d3 && d9 && !d1)
{ {
return partialHide->ourImages[20].bitmap; //visible corners without left bottom return partialHide->ourImages[20].bitmap; //visible corners without left bottom
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && !d8 && d7 && !d3 && d9 && d1)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[20].bitmap); //visible corners without right bottom //return CSDL_Ext::rotate01(partialHide->ourImages[20].bitmap); //visible corners without right bottom
return partialHide->ourImages[42].bitmap; return partialHide->ourImages[42].bitmap;
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && !d8 && d7 && d3 && !d9 && d1)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[19].bitmap); //visible corners without right top //return CSDL_Ext::rotate01(partialHide->ourImages[19].bitmap); //visible corners without right top
return partialHide->ourImages[43].bitmap; return partialHide->ourImages[43].bitmap;
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && !d8 && d7 && d3 && d9 && d1)
{ {
return partialHide->ourImages[21].bitmap; //visible all corners only return partialHide->ourImages[21].bitmap; //visible all corners only
} }
if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl]) if(d2 && d6 && d4 && !d8)
{ {
return partialHide->ourImages[6].bitmap; //hidden top return partialHide->ourImages[6].bitmap; //hidden top
} }
if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) if(d2 && !d6 && d4 && d8)
{ {
return partialHide->ourImages[7].bitmap; //hidden right return partialHide->ourImages[7].bitmap; //hidden right
} }
if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) if(!d2 && d6 && d4 && d8)
{ {
return partialHide->ourImages[8].bitmap; //hidden bottom return partialHide->ourImages[8].bitmap; //hidden bottom
} }
if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) if(d2 && d6 && !d4 && d8)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[7].bitmap); //hidden left //return CSDL_Ext::rotate01(partialHide->ourImages[7].bitmap); //hidden left
return partialHide->ourImages[44].bitmap; return partialHide->ourImages[44].bitmap;
} }
if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl]) if(!d2 && d6 && d4 && !d8)
{ {
return partialHide->ourImages[9].bitmap; //hidden top and bottom return partialHide->ourImages[9].bitmap; //hidden top and bottom
} }
if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) if(d2 && !d6 && !d4 && d8)
{ {
return partialHide->ourImages[29].bitmap; //hidden left and right return partialHide->ourImages[29].bitmap; //hidden left and right
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && d8 && d3 && !d1)
{ {
return partialHide->ourImages[24].bitmap; //visible top and right bottom corner return partialHide->ourImages[24].bitmap; //visible top and right bottom corner
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && d8 && !d3 && d1)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[24].bitmap); //visible top and left bottom corner //return CSDL_Ext::rotate01(partialHide->ourImages[24].bitmap); //visible top and left bottom corner
return partialHide->ourImages[45].bitmap; return partialHide->ourImages[45].bitmap;
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x-1][y+1][lvl]) if(!d2 && !d6 && !d4 && d8 && d3 && d1)
{ {
return partialHide->ourImages[33].bitmap; //visible top and bottom corners return partialHide->ourImages[33].bitmap; //visible top and bottom corners
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl]) if(!d2 && !d6 && d4 && !d8 && !d3 && d9)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[26].bitmap); //visible left and right top corner //return CSDL_Ext::rotate01(partialHide->ourImages[26].bitmap); //visible left and right top corner
return partialHide->ourImages[46].bitmap; return partialHide->ourImages[46].bitmap;
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl]) if(!d2 && !d6 && d4 && !d8 && d3 && !d9)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[25].bitmap); //visible left and right bottom corner //return CSDL_Ext::rotate01(partialHide->ourImages[25].bitmap); //visible left and right bottom corner
return partialHide->ourImages[47].bitmap; return partialHide->ourImages[47].bitmap;
} }
if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl]) if(!d2 && !d6 && d4 && !d8 && d3 && d9)
{ {
return partialHide->ourImages[32].bitmap; //visible left and right corners return partialHide->ourImages[32].bitmap; //visible left and right corners
} }
if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y-1][lvl]) if(d2 && !d6 && !d4 && !d8 && d7 && !d9)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[30].bitmap); //visible bottom and left top corner //return CSDL_Ext::rotate01(partialHide->ourImages[30].bitmap); //visible bottom and left top corner
return partialHide->ourImages[48].bitmap; return partialHide->ourImages[48].bitmap;
} }
if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y-1][lvl]) if(d2 && !d6 && !d4 && !d8 && !d7 && d9)
{ {
return partialHide->ourImages[30].bitmap; //visible bottom and right top corner return partialHide->ourImages[30].bitmap; //visible bottom and right top corner
} }
if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y-1][lvl]) if(d2 && !d6 && !d4 && !d8 && d7 && d9)
{ {
return partialHide->ourImages[31].bitmap; //visible bottom and top corners return partialHide->ourImages[31].bitmap; //visible bottom and top corners
} }
if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) if(!d2 && d6 && !d4 && !d8 && !d7 && d1)
{ {
return partialHide->ourImages[25].bitmap; //visible right and left bottom corner return partialHide->ourImages[25].bitmap; //visible right and left bottom corner
} }
if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) if(!d2 && d6 && !d4 && !d8 && d7 && !d1)
{ {
return partialHide->ourImages[26].bitmap; //visible right and left top corner return partialHide->ourImages[26].bitmap; //visible right and left top corner
} }
if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) if(!d2 && d6 && !d4 && !d8 && d7 && d1)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[32].bitmap); //visible right and left cornres //return CSDL_Ext::rotate01(partialHide->ourImages[32].bitmap); //visible right and left cornres
return partialHide->ourImages[49].bitmap; return partialHide->ourImages[49].bitmap;
} }
if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl]) if(d2 && d6 && !d4 && !d8 && d7)
{ {
return partialHide->ourImages[28].bitmap; //visible bottom, right - bottom, right; left top corner visible return partialHide->ourImages[28].bitmap; //visible bottom, right - bottom, right; left top corner visible
} }
else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) else if(!d2 && d6 && !d4 && d8 && d1)
{ {
return partialHide->ourImages[27].bitmap; //visible right, right - top; left bottom corner visible return partialHide->ourImages[27].bitmap; //visible right, right - top; left bottom corner visible
} }
else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl]) else if(!d2 && !d6 && d4 && d8 && d3)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[27].bitmap); //visible top, top - left, left; right bottom corner visible //return CSDL_Ext::rotate01(partialHide->ourImages[27].bitmap); //visible top, top - left, left; right bottom corner visible
return partialHide->ourImages[50].bitmap; return partialHide->ourImages[50].bitmap;
} }
else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y-1][lvl]) else if(d2 && !d6 && d4 && !d8 && d9)
{ {
//return CSDL_Ext::rotate01(partialHide->ourImages[28].bitmap); //visible left, left - bottom, bottom; right top corner visible //return CSDL_Ext::rotate01(partialHide->ourImages[28].bitmap); //visible left, left - bottom, bottom; right top corner visible
return partialHide->ourImages[51].bitmap; return partialHide->ourImages[51].bitmap;
} }
//newly added //newly added
else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible t and tr else if(!d2 && !d6 && !d4 && d8 && !d7 && !d3 && d9 && !d1) //visible t and tr
{ {
return partialHide->ourImages[0].bitmap; return partialHide->ourImages[0].bitmap;
} }
else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible t and tl else if(!d2 && !d6 && !d4 && d8 && d7 && !d3 && !d9 && !d1) //visible t and tl
{ {
return partialHide->ourImages[1].bitmap; return partialHide->ourImages[1].bitmap;
} }
else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible b and br else if(d2 && !d6 && !d4 && !d8 && !d7 && d3 && !d9 && !d1) //visible b and br
{ {
return partialHide->ourImages[4].bitmap; return partialHide->ourImages[4].bitmap;
} }
else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) //visible b and bl else if(d2 && !d6 && !d4 && !d8 && !d7 && !d3 && !d9 && d1) //visible b and bl
{ {
return partialHide->ourImages[5].bitmap; return partialHide->ourImages[5].bitmap;
} }
else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible l and tl else if(!d2 && !d6 && d4 && !d8 && d7 && !d3 && !d9 && !d1) //visible l and tl
{ {
return partialHide->ourImages[36].bitmap; return partialHide->ourImages[36].bitmap;
} }
else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) //visible l and bl else if(!d2 && !d6 && d4 && !d8 && !d7 && !d3 && !d9 && d1) //visible l and bl
{ {
return partialHide->ourImages[36].bitmap; return partialHide->ourImages[36].bitmap;
} }
else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible r and tr else if(!d2 && d6 && !d4 && !d8 && !d7 && !d3 && d9 && !d1) //visible r and tr
{ {
return partialHide->ourImages[2].bitmap; return partialHide->ourImages[2].bitmap;
} }
else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible r and br else if(!d2 && d6 && !d4 && !d8 && !d7 && d3 && !d9 && !d1) //visible r and br
{ {
return partialHide->ourImages[3].bitmap; return partialHide->ourImages[3].bitmap;
} }

View File

@ -41,6 +41,18 @@ template <typename T> class PseudoV
public: public:
int offset; int offset;
std::vector<T> inver; std::vector<T> inver;
PseudoV(){};
PseudoV(std::vector<T> &src, int offset, const T& fill)
{
inver.resize(Offset*2+rest);
offset=Offset;
for(int i=0; i<offset;i++)
inver[i] = fill;
for(int i=0;i<src.size();i++)
inver[offset+i] = src[i];
for(int i=src.size(); i<src.size()+offset;i++)
inver[offset+i] = fill;
}
inline T & operator[](int n) inline T & operator[](int n)
{ {
return inver[n+offset]; return inver[n+offset];
@ -65,24 +77,23 @@ public:
CDefHandler * fullHide; CDefHandler * fullHide;
CDefHandler * partialHide; CDefHandler * partialHide;
PseudoV< PseudoV< PseudoV<unsigned char> > > visibility; //true means that pointed place is visible //not used now std::vector< std::vector< std::vector<unsigned char> > > visibility; //true means that pointed place is visible //not used now
//std::vector< std::vector<char> > undVisibility; //true means that pointed place is visible //std::vector< std::vector<char> > undVisibility; //true means that pointed place is visible
std::vector<CDefHandler *> roadDefs; std::vector<CDefHandler *> roadDefs;
std::vector<CDefHandler *> staticRiverDefs; std::vector<CDefHandler *> staticRiverDefs;
std::vector<CDefHandler*> defs; std::vector<CDefHandler*> defs;
std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase) std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
std::map<int, CGDefInfo*> villages, forts, capitols;
std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type
std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle
PseudoV< PseudoV< PseudoV<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile std::vector<std::vector<std::vector<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
void loadDefs(); void loadDefs();
char & visAccess(int x, int y); char & visAccess(int x, int y);
char & undVisAccess(int x, int y); char & undVisAccess(int x, int y);
SDL_Surface mirrorImage(SDL_Surface *src); //what is this?? SDL_Surface mirrorImage(SDL_Surface *src); //what is this??
SDL_Surface * getVisBitmap(int x, int y, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap, int lvl); SDL_Surface * getVisBitmap(int x, int y, std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl);
int getCost(int3 & a, int3 & b, const CGHeroInstance * hero); int getCost(int3 & a, int3 & b, const CGHeroInstance * hero);
std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
@ -105,7 +116,7 @@ public:
void prepareFOWDefs(); void prepareFOWDefs();
void randomizeObjects(); void randomizeObjects();
SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap = CGI->mh->visibility, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap = CGI->mh->visibility, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it
SDL_Surface * terrBitmap(int x, int y); SDL_Surface * terrBitmap(int x, int y);
SDL_Surface * undTerrBitmap(int x, int y); SDL_Surface * undTerrBitmap(int x, int y);
std::string getRandomizedDefName(CGDefInfo* di, CGObjectInstance * obj = NULL); //objinstance needed only for heroes and towns std::string getRandomizedDefName(CGDefInfo* di, CGObjectInstance * obj = NULL); //objinstance needed only for heroes and towns