1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Fighting with includes.

This commit is contained in:
Michał W. Urbańczyk
2008-07-02 08:39:56 +00:00
parent b0002ff50b
commit 1b73678b7c
19 changed files with 175 additions and 154 deletions

View File

@ -20,6 +20,8 @@
#include "AdventureMapButton.h" #include "AdventureMapButton.h"
#include "CHeroWindow.h" #include "CHeroWindow.h"
#include "client/Graphics.h" #include "client/Graphics.h"
#include "hch/CObjectHandler.h"
#include "map.h"
#pragma warning (disable : 4355) #pragma warning (disable : 4355)
extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
@ -558,7 +560,7 @@ void CTerrainRect::show()
SDL_Surface * teren = CGI->mh->terrainRect SDL_Surface * teren = CGI->mh->terrainRect
(LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y, (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim, tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim,
LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim, &LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
screen,&genRect(547,594,7,6) screen,&genRect(547,594,7,6)
); );
//SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6)); //SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));

View File

@ -4,6 +4,7 @@
#include "SDL_Extensions.h" #include "SDL_Extensions.h"
#include "CAdvmapInterface.h" #include "CAdvmapInterface.h"
#include "AdventureMapButton.h" #include "AdventureMapButton.h"
#include "hch/CObjectHandler.h"
#include "hch/CHeroHandler.h" #include "hch/CHeroHandler.h"
#include "hch/CDefHandler.h" #include "hch/CDefHandler.h"
#include "CCallback.h" #include "CCallback.h"
@ -35,7 +36,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
creDir[b->second.ID] = b->second.owner==attackingHeroInstance->tempOwner; creDir[b->second.ID] = b->second.owner==attackingHeroInstance->tempOwner;
} }
//preparing menu background and terrain //preparing menu background and terrain
std::vector< std::string > & backref = CGI->mh->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ]; std::vector< std::string > & backref = graphics->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");
graphics->blueToPlayersAdv(menu, hero1->tempOwner); graphics->blueToPlayersAdv(menu, hero1->tempOwner);
@ -81,7 +82,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
//loading hero animations //loading hero animations
if(hero1) // attacking hero if(hero1) // attacking hero
{ {
attackingHero = new CBattleHero(CGI->mh->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner); attackingHero = new CBattleHero(graphics->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner);
attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40, 0); attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40, 0);
} }
else else
@ -90,7 +91,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
} }
if(hero2) // defending hero if(hero2) // defending hero
{ {
defendingHero = new CBattleHero(CGI->mh->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner); defendingHero = new CBattleHero(graphics->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner);
defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690, 0); defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690, 0);
} }
else else
@ -323,7 +324,7 @@ bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
} }
creDir[number] = !creDir[number]; creDir[number] = !creDir[number];
CStack curs = LOCPLINT->cb->battleGetStackByID(number); CStack curs = *LOCPLINT->cb->battleGetStackByID(number);
std::pair <int, int> coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs.creature); std::pair <int, int> coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs.creature);
creAnims[number]->pos.x = coords.first; creAnims[number]->pos.x = coords.first;
//creAnims[number]->pos.y = coords.second; //creAnims[number]->pos.y = coords.second;
@ -504,7 +505,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo
CSDL_Ext::update(); CSDL_Ext::update();
SDL_framerateDelay(LOCPLINT->mainFPSmng); SDL_framerateDelay(LOCPLINT->mainFPSmng);
} }
if( (LOCPLINT->cb->battleGetStackByID(number).owner == attackingHeroInstance->tempOwner ) != creDir[number]) if( (LOCPLINT->cb->battleGetStackByID(number)->owner == attackingHeroInstance->tempOwner ) != creDir[number])
{ {
reverseCreature(number, curStackPos, true); reverseCreature(number, curStackPos, true);
} }
@ -585,7 +586,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo
} }
creAnims[number]->setType(2); //resetting to default creAnims[number]->setType(2); //resetting to default
CStack curs = LOCPLINT->cb->battleGetStackByID(number); CStack curs = *LOCPLINT->cb->battleGetStackByID(number);
if(endMoving) //resetting to default if(endMoving) //resetting to default
{ {
if(creDir[number] != (curs.owner == attackingHeroInstance->tempOwner)) if(creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))
@ -614,7 +615,7 @@ void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby)
void CBattleInterface::stackAttacking(int ID, int dest) void CBattleInterface::stackAttacking(int ID, int dest)
{ {
CStack aStack = LOCPLINT->cb->battleGetStackByID(ID); //attacking stack CStack aStack = *LOCPLINT->cb->battleGetStackByID(ID); //attacking stack
if(aStack.creature->isDoubleWide()) if(aStack.creature->isDoubleWide())
{ {
switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
@ -733,7 +734,7 @@ void CBattleInterface::hexLclicked(int whichOne)
ba->stackNumber = activeStack; ba->stackNumber = activeStack;
givenCommand = ba; givenCommand = ba;
} }
else if(LOCPLINT->cb->battleGetStackByID(atCre).owner != attackingHeroInstance->tempOwner) //attacking else if(LOCPLINT->cb->battleGetStackByID(atCre)->owner != attackingHeroInstance->tempOwner) //attacking
{ {
BattleAction * ba = new BattleAction(); //to be deleted by engine BattleAction * ba = new BattleAction(); //to be deleted by engine
ba->actionType = 6; ba->actionType = 6;
@ -760,7 +761,7 @@ void CBattleInterface::attackingShowHelper()
{ {
if(attackingInfo->frame == 0) if(attackingInfo->frame == 0)
{ {
CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
if(aStack.creature->isDoubleWide()) if(aStack.creature->isDoubleWide())
{ {
switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
@ -813,7 +814,7 @@ void CBattleInterface::attackingShowHelper()
else if(attackingInfo->frame == (attackingInfo->maxframe - 1)) else if(attackingInfo->frame == (attackingInfo->maxframe - 1))
{ {
attackingInfo->reversing = true; attackingInfo->reversing = true;
CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
if(aStack.creature->isDoubleWide()) if(aStack.creature->isDoubleWide())
{ {
switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
@ -871,8 +872,8 @@ void CBattleInterface::attackingShowHelper()
void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDby) void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDby)
{ {
char tabh[200]; char tabh[200];
CStack attacker = LOCPLINT->cb->battleGetStackByID(IDby); CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby);
CStack defender = LOCPLINT->cb->battleGetStackByID(ID); CStack defender = *LOCPLINT->cb->battleGetStackByID(ID);
int end = sprintf(tabh, CGI->generaltexth->allTexts[attacker.amount > 1 ? 377 : 376].c_str(), int end = sprintf(tabh, CGI->generaltexth->allTexts[attacker.amount > 1 ? 377 : 376].c_str(),
(attacker.amount > 1 ? attacker.creature->namePl.c_str() : attacker.creature->nameSing.c_str()), (attacker.amount > 1 ? attacker.creature->namePl.c_str() : attacker.creature->nameSing.c_str()),
dmg); dmg);
@ -1054,11 +1055,11 @@ void CBattleHex::mouseMoved(SDL_MouseMotionEvent &sEvent)
if(hovered && strictHovered) //print attacked creature to console if(hovered && strictHovered) //print attacked creature to console
{ {
if(myInterface->console->alterTxt.size() == 0 && LOCPLINT->cb->battleGetStack(myNumber) != -1 && if(myInterface->console->alterTxt.size() == 0 && LOCPLINT->cb->battleGetStack(myNumber) != -1 &&
LOCPLINT->cb->battleGetStackByPos(myNumber).owner != LOCPLINT->playerID && LOCPLINT->cb->battleGetStackByPos(myNumber)->owner != LOCPLINT->playerID &&
LOCPLINT->cb->battleGetStackByPos(myNumber).alive) LOCPLINT->cb->battleGetStackByPos(myNumber)->alive)
{ {
char tabh[160]; char tabh[160];
CStack attackedStack = LOCPLINT->cb->battleGetStackByPos(myNumber); CStack attackedStack = *LOCPLINT->cb->battleGetStackByPos(myNumber);
std::string attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl; std::string attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl;
sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str());
myInterface->console->alterTxt = std::string(tabh); myInterface->console->alterTxt = std::string(tabh);
@ -1085,7 +1086,7 @@ void CBattleHex::clickRight(boost::logic::tribool down)
int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile
if(hovered && strictHovered && stID!=-1) if(hovered && strictHovered && stID!=-1)
{ {
CStack myst = LOCPLINT->cb->battleGetStackByID(stID); //stack info CStack myst = *LOCPLINT->cb->battleGetStackByID(stID); //stack info
StackState *pom = NULL; StackState *pom = NULL;
if(down) if(down)
{ {

View File

@ -13,6 +13,7 @@
#include "CAdvmapInterface.h" #include "CAdvmapInterface.h"
#include "CPlayerInterface.h" #include "CPlayerInterface.h"
#include "hch/CBuildingHandler.h" #include "hch/CBuildingHandler.h"
#include "hch/CObjectHandler.h"
LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
int CCallback::lowestSpeed(CGHeroInstance * chi) int CCallback::lowestSpeed(CGHeroInstance * chi)
@ -783,17 +784,17 @@ int CCallback::battleGetStack(int pos)
return -1; return -1;
} }
CStack CCallback::battleGetStackByID(int ID) CStack* CCallback::battleGetStackByID(int ID)
{ {
for(int g=0; g<CGI->state->curB->stacks.size(); ++g) for(int g=0; g<CGI->state->curB->stacks.size(); ++g)
{ {
if(CGI->state->curB->stacks[g]->ID == ID) if(CGI->state->curB->stacks[g]->ID == ID)
return *(CGI->state->curB->stacks[g]); return CGI->state->curB->stacks[g];
} }
return CStack(); return NULL;
} }
CStack CCallback::battleGetStackByPos(int pos) CStack* CCallback::battleGetStackByPos(int pos)
{ {
return battleGetStackByID(battleGetStack(pos)); return battleGetStackByID(battleGetStack(pos));
} }

View File

@ -1,19 +1,22 @@
#ifndef CCALLBACK_H #ifndef CCALLBACK_H
#define CCALLBACK_H #define CCALLBACK_H
#include "mapHandler.h" #include "global.h"
#include "tchar.h" #include "tchar.h"
#include "CGameState.h" #include <set>
class CGHeroInstance;
class CGameState; class CGameState;
struct CPath; struct CPath;
class CGObjectInstance; class CGObjectInstance;
class CArmedInstance;
class SComponent; class SComponent;
class IChosen; class IChosen;
class CSelectableComponent; class CSelectableComponent;
struct BattleAction; struct BattleAction;
typedef struct lua_State lua_State; class CGTownInstance;
struct StartInfo;
class CStack;
struct lua_State;
//structure gathering info about upgrade possibilites //structure gathering info about upgrade possibilites
struct UpgradeInfo struct UpgradeInfo
{ {
@ -60,8 +63,8 @@ public:
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
virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield
virtual int battleGetStack(int pos)=0; //returns ID of stack on the tile virtual int battleGetStack(int pos)=0; //returns ID of stack on the tile
virtual CStack battleGetStackByID(int ID)=0; //returns stack info by given ID virtual CStack * battleGetStackByID(int ID)=0; //returns stack info by given ID
virtual CStack battleGetStackByPos(int pos)=0; //returns stack info by given pos virtual CStack * battleGetStackByPos(int pos)=0; //returns stack info by given pos
virtual int battleGetPos(int stack)=0; //returns position (tile ID) of stack virtual int battleGetPos(int stack)=0; //returns position (tile ID) of stack
//virtual int battleMakeAction(BattleAction* action)=0;//perform action with an active stack (or custom action) //virtual int battleMakeAction(BattleAction* action)=0;//perform action with an active stack (or custom action)
virtual std::map<int, CStack> battleGetStacks()=0; //returns stacks on battlefield virtual std::map<int, CStack> battleGetStacks()=0; //returns stacks on battlefield
@ -133,8 +136,8 @@ public:
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
int battleGetObstaclesAtTile(int tile); //returns bitfield int battleGetObstaclesAtTile(int tile); //returns bitfield
int battleGetStack(int pos); //returns ID of stack on the tile int battleGetStack(int pos); //returns ID of stack on the tile
CStack battleGetStackByID(int ID); //returns stack info by given ID CStack * battleGetStackByID(int ID); //returns stack info by given ID
CStack battleGetStackByPos(int pos); //returns stack info by given pos CStack * battleGetStackByPos(int pos); //returns stack info by given pos
int battleGetPos(int stack); //returns position (tile ID) of stack int battleGetPos(int stack); //returns position (tile ID) of stack
//int battleMakeAction(BattleAction* action);//perform action with an active stack (or custom action) //int battleMakeAction(BattleAction* action);//perform action with an active stack (or custom action)
std::map<int, CStack> battleGetStacks(); //returns stacks on battlefield std::map<int, CStack> battleGetStacks(); //returns stacks on battlefield

View File

@ -8,6 +8,7 @@
#include "hch/CTownHandler.h" #include "hch/CTownHandler.h"
#include "AdventureMapButton.h" #include "AdventureMapButton.h"
#include "hch/CBuildingHandler.h" #include "hch/CBuildingHandler.h"
#include "hch/CDefHandler.h"
#include <sstream> #include <sstream>
#include "CMessage.h" #include "CMessage.h"
#include "hch/CGeneralTextHandler.h" #include "hch/CGeneralTextHandler.h"

View File

@ -91,15 +91,15 @@ int internalFunc(void * callback)
// readed>>heronum; // readed>>heronum;
// std::cout<<"Position of hero "<<heronum<<": "<<CGI->heroh->heroInstances[heronum]->getPosition(false)<<std::endl; // std::cout<<"Position of hero "<<heronum<<": "<<CGI->heroh->heroInstances[heronum]->getPosition(false)<<std::endl;
// break; // break;
case 'M': //move heroa //case 'M': //move heroa
{ // {
readed>>heronum>>dest; // readed>>heronum>>dest;
const CGHeroInstance * hero = cb->getHeroInfo(0,heronum,0); // const CGHeroInstance * hero = cb->getHeroInfo(0,heronum,0);
p = CGI->pathf->GetPath(Coordinate(hero->getPosition(false)),Coordinate(dest),hero); // p = CGI->pathf->GetPath(Coordinate(hero->getPosition(false)),Coordinate(dest),hero);
cb->moveHero(heronum, CGI->pathf->ConvertToOldFormat(p), 0, 0); // cb->moveHero(heronum, CGI->pathf->ConvertToOldFormat(p), 0, 0);
//LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]); // //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
break; // break;
} // }
case 'D': //pos description case 'D': //pos description
readed>>src; readed>>src;
CGI->mh->getObjDescriptions(src); CGI->mh->getObjDescriptions(src);

View File

@ -1,8 +1,6 @@
#ifndef CGAMEINFO_H #ifndef CGAMEINFO_H
#define CGAMEINFO_H #define CGAMEINFO_H
#include "global.h"
#include "StartInfo.h"
#include "SDL.h"
#include <vector> #include <vector>

View File

@ -105,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 CMapHandler; friend class CMapHandler;
}; };
#endif //CGAMESTATE_H #endif //CGAMESTATE_H

View File

@ -14,6 +14,8 @@
#include "CCallback.h" #include "CCallback.h"
#include "hch/CArtHandler.h" #include "hch/CArtHandler.h"
#include "hch/CAbilityHandler.h" #include "hch/CAbilityHandler.h"
#include "hch/CDefHandler.h"
#include "client/CBitmapHandler.h"
#include <sstream> #include <sstream>
#include "client/Graphics.h" #include "client/Graphics.h"
extern SDL_Surface * screen; extern SDL_Surface * screen;

View File

@ -21,6 +21,8 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include "hch/CDefObjInfoHandler.h" #include "hch/CDefObjInfoHandler.h"
#include "map.h"
#include "maphandler.h"
#pragma warning (disable : 4311) #pragma warning (disable : 4311)
bool getGlobalFunc(lua_State * L, std::string fname) bool getGlobalFunc(lua_State * L, std::string fname)
{ {

View File

@ -61,7 +61,7 @@ void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * sc
} }
int _tmain(int argc, _TCHAR* argv[]) int _tmain(int argc, _TCHAR* argv[])
{ {
boost::thread servthr(boost::bind(system,"Debug\\VCMI_server.exe")); boost::thread servthr(boost::bind(system,"VCMI_server.exe"));
/* /*
boost::asio::io_service io_service; boost::asio::io_service io_service;
boost::system::error_code error = boost::asio::error::host_not_found; boost::system::error_code error = boost::asio::error::host_not_found;

View File

@ -5,6 +5,7 @@
#include "hch/CAmbarCendamo.h" #include "hch/CAmbarCendamo.h"
#include "mapHandler.h" #include "mapHandler.h"
#include "CGameState.h" #include "CGameState.h"
#include "hch/CObjectHandler.h"
using namespace std; using namespace std;

View File

@ -23,11 +23,14 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include "hch/CPreGameTextHandler.h" #include "hch/CPreGameTextHandler.h"
#include "hch/CObjectHandler.h"
#include "CBattleInterface.h" #include "CBattleInterface.h"
#include "CGameInfo.h"
#include "CLua.h" #include "CLua.h"
#include <cmath> #include <cmath>
#include "client/CCreatureAnimation.h" #include "client/CCreatureAnimation.h"
#include "client/Graphics.h" #include "client/Graphics.h"
#include "map.h"
using namespace CSDL_Ext; using namespace CSDL_Ext;
extern TTF_Font * GEOR16; extern TTF_Font * GEOR16;

View File

@ -111,6 +111,31 @@ void Graphics::loadPaletteAndColors()
playerColors[i].unused = 0; playerColors[i].unused = 0;
} }
neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84;//gray neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84;//gray
}
void Graphics::initializeBattleGraphics()
{
std::ifstream bback("config/battleBack.txt");
battleBacks.resize(9);
for(int i=0; i<9; ++i) //9 - number of terrains battle can be fought on
{
int am;
bback>>am;
battleBacks[i].resize(am);
for(int f=0; f<am; ++f)
{
bback>>battleBacks[i][f];
}
}
//initializing battle hero animation
std::ifstream bher("config/battleHeroes.txt");
int numberofh;
bher>>numberofh;
battleHeroes.resize(numberofh);
for(int i=0; i<numberofh; ++i) //9 - number of terrains battle can be fought on
{
bher>>battleHeroes[i];
}
} }
Graphics::Graphics() Graphics::Graphics()
{ {
@ -128,6 +153,7 @@ Graphics::Graphics()
tasks += boost::bind(&Graphics::loadPaletteAndColors,this); 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 += boost::bind(&Graphics::initializeBattleGraphics,this);
tasks += GET_SURFACE(hInfo,"HEROQVBK.bmp"); tasks += GET_SURFACE(hInfo,"HEROQVBK.bmp");
tasks += GET_SURFACE(tInfo,"TOWNQVBK.bmp"); tasks += GET_SURFACE(tInfo,"TOWNQVBK.bmp");
tasks += GET_DEF(artDefs,"ARTIFACT.DEF"); tasks += GET_DEF(artDefs,"ARTIFACT.DEF");

View File

@ -32,9 +32,12 @@ public:
std::map<int,SDL_Surface*> smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border std::map<int,SDL_Surface*> smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border
std::map<int,SDL_Surface*> bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border std::map<int,SDL_Surface*> bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border
std::map<int,SDL_Surface*> backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral std::map<int,SDL_Surface*> backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral
//for battles
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
//functions //functions
Graphics(); Graphics();
void initializeBattleGraphics();
void loadPaletteAndColors(); void loadPaletteAndColors();
void loadHeroFlags(); void loadHeroFlags();
void loadHeroFlags(std::pair<std::vector<CDefHandler *> Graphics::*, std::vector<const char *> > &pr, bool mode); void loadHeroFlags(std::pair<std::vector<CDefHandler *> Graphics::*, std::vector<const char *> > &pr, bool mode);

View File

@ -13,6 +13,8 @@
#include "client\Graphics.h" #include "client\Graphics.h"
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
#include "hch/CObjectHandler.h"
#include "map.h"
extern SDL_Surface * screen; extern SDL_Surface * screen;
std::string nameFromType (EterrainType typ) std::string nameFromType (EterrainType typ)
{ {
@ -637,33 +639,9 @@ void CMapHandler::init()
std::cout<<"\tMaking object rects: "<<th.getDif()<<std::endl; std::cout<<"\tMaking object rects: "<<th.getDif()<<std::endl;
calculateBlockedPos(); calculateBlockedPos();
std::cout<<"\tCalculating blockmap: "<<th.getDif()<<std::endl; std::cout<<"\tCalculating blockmap: "<<th.getDif()<<std::endl;
//initailizing battle backgrounds
std::ifstream bback("config/battleBack.txt");
battleBacks.resize(9);
for(int i=0; i<9; ++i) //9 - number of terrains battle can be fought on
{
int am;
bback>>am;
battleBacks[i].resize(am);
for(int f=0; f<am; ++f)
{
bback>>battleBacks[i][f];
}
}
//initializing battle hero animation
std::ifstream bher("config/battleHeroes.txt");
int numberofh;
bher>>numberofh;
battleHeroes.resize(numberofh);
for(int i=0; i<numberofh; ++i) //9 - number of terrains battle can be fought on
{
bher>>battleHeroes[i];
}
} }
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) 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
@ -831,9 +809,9 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
sr.h=sr.w=32; sr.h=sr.w=32;
validateRectTerr(&sr, extRect); validateRectTerr(&sr, extRect);
if(bx+x>=0 && by+y>=0 && bx+x<CGI->mh->map->width && by+y<CGI->mh->map->height && !visibilityMap[bx+x][by+y][level]) if(bx+x>=0 && by+y>=0 && bx+x<CGI->mh->map->width && by+y<CGI->mh->map->height && !(*visibilityMap)[bx+x][by+y][level])
{ {
SDL_Surface * hide = getVisBitmap(bx+x, by+y, visibilityMap, level); SDL_Surface * hide = getVisBitmap(bx+x, by+y, *visibilityMap, level);
CSDL_Ext::blit8bppAlphaTo24bpp(hide, &genRect(sr.h, sr.w, 0, 0), su, &sr); CSDL_Ext::blit8bppAlphaTo24bpp(hide, &genRect(sr.h, sr.w, 0, 0), su, &sr);
} }
} }

View File

@ -1,15 +1,19 @@
#ifndef MAPHANDLER_H #ifndef MAPHANDLER_H
#define MAPHANDLER_H #define MAPHANDLER_H
#include "global.h"
#include "hch/CAmbarCendamo.h" #include <SDL.h>
#include "CGameInfo.h"
#include "hch/CDefHandler.h" #include "hch/CDefHandler.h"
#include <boost/logic/tribool.hpp> #include <boost/logic/tribool.hpp>
#include "hch/CObjectHandler.h"
#include <list> #include <list>
#include <set>
const int Woff = 12; //width of map's frame const int Woff = 12; //width of map's frame
const int Hoff = 8; const int Hoff = 8;
class CGObjectInstance;
class CGHeroInstance;
struct Mapa;
class CGDefInfo;
struct TerrainTile2 struct TerrainTile2
{ {
int3 pos; //this tile's position int3 pos; //this tile's position
@ -84,15 +88,12 @@ public:
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::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::vector<std::vector<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 * getVisBitmap(int x, int y, std::vector< std::vector< std::vector<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);
@ -116,7 +117,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, 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 * 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 = NULL, 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

View File

@ -17,7 +17,7 @@
<Configurations> <Configurations>
<Configuration <Configuration
Name="Debug|Win32" Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)" OutputDirectory="$(SolutionDir)"
IntermediateDirectory="$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1" ConfigurationType="1"
CharacterSet="2" CharacterSet="2"

View File

@ -4,78 +4,77 @@
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include "../global.h" #include "../global.h"
std::string NAME = NAME_VER + std::string(" (server)"); std::string NAME = NAME_VER + std::string(" (server)");
//using boost::asio::ip::tcp; using boost::asio::ip::tcp;
//using namespace boost; using namespace boost;
//using namespace boost::asio; using namespace boost::asio;
//
//class CConnection class CConnection
//{ {
//public: public:
// int ID; int ID;
// tcp::socket socket; tcp::socket socket;
// void witaj() void witaj()
// { {
// char message[50]; strcpy_s(message,50,NAME.c_str());message[NAME.size()]='\n'; char message[50]; strcpy(message,NAME.c_str());message[NAME.size()]='\n';
// write(socket,buffer("Aiya!\n")); write(socket,buffer("Aiya!\n"));
// write(socket,buffer(message,NAME.size()+1)); write(socket,buffer(message,NAME.size()+1));
// } }
// CConnection(io_service& io_service, int id=-1) CConnection(io_service& io_service, int id=-1)
// : socket(io_service), ID(id) : socket(io_service), ID(id)
// { {
// } }
//}; };
//
//class CVCMIServer class CVCMIServer
//{ {
// tcp::acceptor acceptor; tcp::acceptor acceptor;
// std::vector<CConnection*> connections; std::vector<CConnection*> connections;
//public: public:
// CVCMIServer(io_service& io_service) CVCMIServer(io_service& io_service)
// : acceptor(io_service, tcp::endpoint(tcp::v4(), 3030)) : acceptor(io_service, tcp::endpoint(tcp::v4(), 3030))
// { {
// start_accept(); start_accept();
// } }
// private:
//private: void start_accept()
// void start_accept() {
// { std::cout<<"Listening for connections at port " << acceptor.local_endpoint().port() << std::endl;
// std::cout<<"Listening for connections at port " << acceptor.local_endpoint().port() << std::endl; CConnection * new_connection = new CConnection(acceptor.io_service());
// CConnection * new_connection = new CConnection(acceptor.io_service()); acceptor.accept(new_connection->socket);
// acceptor.accept(new_connection->socket); new_connection->witaj();
// new_connection->witaj(); acceptor.async_accept(new_connection->socket,
// acceptor.async_accept(new_connection->socket, boost::bind(&CVCMIServer::gotConnection, this, new_connection,
// boost::bind(&CVCMIServer::gotConnection, this, new_connection, placeholders::error));
// placeholders::error)); }
// }
// void gotConnection(CConnection * connection,const boost::system::error_code& error)
// void gotConnection(CConnection * connection,const system::error_code& error) {
// { if (!error)
// if (!error) {
// { std::cout<<"Got connection!" << std::endl;
// std::cout<<"Got connection!" << std::endl; connection->witaj();
// connection->witaj(); start_accept();
// start_accept(); }
// } else
// else {
// { std::cout<<"Got connection but there is an error " << std::endl;
// std::cout<<"Got connection but there is an error " << std::endl; }
// } }
// }
// };
//};
//
int main() int main()
{ {
// try try
// { {
// io_service io_service; io_service io_service;
// CVCMIServer server(io_service); CVCMIServer server(io_service);
// io_service.run(); io_service.run();
// } }
// catch (std::exception& e) catch (std::exception& e)
// { {
// std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
// } }
//
return 0; return 0;
} }