mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
* saving and resuming games should work!
(loading from the main menu, saving using "save [NAME]" command)
This commit is contained in:
parent
3474fdaf05
commit
b895fa35cb
@ -38,11 +38,6 @@ extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
|
||||
using namespace boost::logic;
|
||||
using namespace boost::assign;
|
||||
using namespace CSDL_Ext;
|
||||
CAdvMapInt::~CAdvMapInt()
|
||||
{
|
||||
SDL_FreeSurface(bg);
|
||||
delete heroWindow;
|
||||
}
|
||||
CMinimap::CMinimap(bool draw)
|
||||
{
|
||||
int3 mapSizes = LOCPLINT->cb->getMapSize();
|
||||
@ -107,6 +102,11 @@ CMinimap::CMinimap(bool draw)
|
||||
if (draw)
|
||||
redraw();
|
||||
}
|
||||
CMinimap::~CMinimap()
|
||||
{
|
||||
SDL_FreeSurface(radar);
|
||||
SDL_FreeSurface(temps);
|
||||
}
|
||||
void CMinimap::draw()
|
||||
{
|
||||
int3 mapSizes = LOCPLINT->cb->getMapSize();
|
||||
@ -297,7 +297,9 @@ void CMinimap::showTile(const int3 &pos)
|
||||
void CMinimap::hideTile(const int3 &pos)
|
||||
{
|
||||
}
|
||||
CTerrainRect::CTerrainRect():currentPath(NULL)
|
||||
|
||||
CTerrainRect::CTerrainRect()
|
||||
:currentPath(NULL)
|
||||
{
|
||||
tilesw=ADVOPT.tilesW;
|
||||
tilesh=ADVOPT.tilesH;
|
||||
@ -312,6 +314,10 @@ CTerrainRect::CTerrainRect():currentPath(NULL)
|
||||
arrows->ourImages[y].bitmap = CSDL_Ext::alphaTransform(arrows->ourImages[y].bitmap);
|
||||
}
|
||||
}
|
||||
CTerrainRect::~CTerrainRect()
|
||||
{
|
||||
delete arrows;
|
||||
}
|
||||
void CTerrainRect::activate()
|
||||
{
|
||||
ClickableL::activate();
|
||||
@ -805,6 +811,7 @@ int3 CTerrainRect::whichTileIsIt()
|
||||
{
|
||||
return whichTileIsIt(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
|
||||
}
|
||||
|
||||
void CResDataBar::clickRight (tribool down)
|
||||
{
|
||||
}
|
||||
@ -1111,6 +1118,15 @@ townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlis
|
||||
gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[3]));
|
||||
}
|
||||
|
||||
CAdvMapInt::~CAdvMapInt()
|
||||
{
|
||||
SDL_FreeSurface(bg);
|
||||
delete heroWindow;
|
||||
|
||||
for(int i=0; i<gems.size(); i++)
|
||||
delete gems[i];
|
||||
}
|
||||
|
||||
void CAdvMapInt::fshowOverview()
|
||||
{
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ public:
|
||||
std::string statusbarTxt, rcText;
|
||||
|
||||
CMinimap(bool draw=true);
|
||||
~CMinimap();
|
||||
void draw();
|
||||
void redraw(int level=-1);// (level==-1) => redraw all levels
|
||||
void updateRadar();
|
||||
@ -49,6 +50,7 @@ public:
|
||||
|
||||
CDefHandler * arrows;
|
||||
CTerrainRect();
|
||||
~CTerrainRect();
|
||||
CPath * currentPath;
|
||||
void activate();
|
||||
void deactivate();
|
||||
|
@ -1032,6 +1032,7 @@ CPlayerInterface::CPlayerInterface(int Player, int serial)
|
||||
playerID=Player;
|
||||
serialID=serial;
|
||||
human=true;
|
||||
adventureInt = NULL;
|
||||
pim = new boost::recursive_mutex;
|
||||
showingDialog = new CondSh<bool>(false);
|
||||
heroMoveSpeed = 2;
|
||||
@ -1046,6 +1047,13 @@ CPlayerInterface::~CPlayerInterface()
|
||||
{
|
||||
delete pim;
|
||||
delete showingDialog;
|
||||
delete mainFPSmng;
|
||||
delete adventureInt;
|
||||
|
||||
for(std::map<int,SDL_Surface*>::iterator i=graphics->heroWins.begin(); i!= graphics->heroWins.end(); i++)
|
||||
SDL_FreeSurface(i->second);
|
||||
for(std::map<int,SDL_Surface*>::iterator i=graphics->townWins.begin(); i!= graphics->townWins.end(); i++)
|
||||
SDL_FreeSurface(i->second);
|
||||
}
|
||||
void CPlayerInterface::init(ICallback * CB)
|
||||
{
|
||||
|
19
CPreGame.cpp
19
CPreGame.cpp
@ -1,6 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "CPreGame.h"
|
||||
#include "hch/CDefHandler.h"
|
||||
#include <ctime>
|
||||
#include <SDL.h>
|
||||
#include <boost/filesystem.hpp> // includes all needed Boost.Filesystem declarations
|
||||
#include <boost/algorithm/string.hpp>
|
||||
@ -992,7 +993,7 @@ void MapSel::show()
|
||||
//blit bg
|
||||
blitAt(bg,3,6);
|
||||
CSDL_Ext::printAt("Map Sizes",55,60,GEOR13);
|
||||
CSDL_Ext::printAt("Select a Scenario to Play",110,25,TNRB16);
|
||||
CSDL_Ext::printAt(CGI->generaltexth->arraytxt[CPG->fromnewgame ? 229 : 230],110,25,TNRB16); //Select a Scenario to Play : Load a Saved Game
|
||||
//size buttons
|
||||
small.show();
|
||||
medium.show();
|
||||
@ -1172,16 +1173,25 @@ void MapSel::init()
|
||||
|
||||
group.join_all();
|
||||
pliczkiTemp.clear();
|
||||
std::vector<std::string> datestemp;
|
||||
tie = fs::path( (fs::initial_path<fs::path>())/"/Games" );
|
||||
for ( fs::directory_iterator dir (tie); dir!=end_iter; ++dir )
|
||||
{
|
||||
if (fs::is_regular_file(dir->status()));
|
||||
{
|
||||
if (boost::ends_with(dir->path().filename(),".vlgm1"))
|
||||
{
|
||||
pliczkiTemp.push_back("Games/"+(dir->path().leaf()));
|
||||
std::time_t time = fs::last_write_time(dir->path());
|
||||
datestemp.push_back(std::asctime(std::gmtime(&time)));
|
||||
}
|
||||
}
|
||||
}
|
||||
processGames(pliczkiTemp,mapInd);
|
||||
for (int i = 0; i < ourGames.size(); i++)
|
||||
{
|
||||
ourGames[i].date = datestemp[i];
|
||||
}
|
||||
}
|
||||
void MapSel::moveByOne(bool up)
|
||||
{
|
||||
@ -1374,6 +1384,8 @@ void MapSel::printSelectedInfo()
|
||||
blitAt(Dloss->ourImages[temp].bitmap,420,366); //l
|
||||
|
||||
CSDL_Ext::printAtMiddle(diff,458,477,GEOR13,zwykly);
|
||||
|
||||
CSDL_Ext::printTo(selMap.date,704,40,GEOR13,zwykly);
|
||||
//SDL_Flip(screen);
|
||||
printFlags();
|
||||
CSDL_Ext::update(screen);
|
||||
@ -1539,7 +1551,7 @@ void CPreGame::showScenSel()
|
||||
SDL_BlitSurface(ourScenSel->bHard.imgs->ourImages[0].bitmap,NULL,screen,&ourScenSel->bHard.pos);
|
||||
SDL_BlitSurface(ourScenSel->bExpert.imgs->ourImages[0].bitmap,NULL,screen,&ourScenSel->bExpert.pos);
|
||||
SDL_BlitSurface(ourScenSel->bImpossible.imgs->ourImages[0].bitmap,NULL,screen,&ourScenSel->bImpossible.pos);
|
||||
SDL_BlitSurface(ourScenSel->bBegin.imgs->ourImages[0].bitmap,NULL,screen,&ourScenSel->bBegin.pos);
|
||||
SDL_BlitSurface((fromnewgame ? ourScenSel->bBegin : ourScenSel->bLoad).imgs->ourImages[0].bitmap,NULL,screen,&ourScenSel->bBegin.pos);
|
||||
SDL_BlitSurface(ourScenSel->bBack.imgs->ourImages[0].bitmap,NULL,screen,&ourScenSel->bBack.pos);
|
||||
//blitAt(ourScenSel->bScens.imgs->ourImages[0].bitmap,ourScenSel->bScens.pos.x,ourScenSel->bScens.pos.y);
|
||||
//blitAt(ourScenSel->bRandom.imgs->ourImages[0].bitmap,414,105);
|
||||
@ -1563,7 +1575,7 @@ void CPreGame::showScenSel()
|
||||
}
|
||||
else
|
||||
ourScenSel->mapsel.show();
|
||||
btns.push_back(&ourScenSel->bBegin);
|
||||
btns.push_back(&(fromnewgame ? ourScenSel->bBegin : ourScenSel->bLoad));
|
||||
btns.push_back(&ourScenSel->bBack);
|
||||
|
||||
ourScenSel->selectedDiff=1;
|
||||
@ -2403,6 +2415,7 @@ ScenSel::ScenSel()
|
||||
bImpossible(genRect(0,0,634,456),NULL,CDefHandler::giveDef("GSPBUT7.DEF"),true,difficulty,4),
|
||||
bBack(genRect(0,0,584,535),boost::bind(&CPreGame::showNewMenu,CPG),CDefHandler::giveDef("SCNRBACK.DEF")),
|
||||
bBegin(genRect(0,0,414,535),boost::bind(&CPreGame::begin,CPG),CDefHandler::giveDef("SCNRBEG.DEF")),
|
||||
bLoad(genRect(0,0,414,535),boost::bind(&CPreGame::begin,CPG),CDefHandler::giveDef("SCNRLOD.DEF")),
|
||||
bScens(genRect(0,0,414,81),boost::bind(&CPreGame::showScenList,CPG),CDefHandler::giveDef("GSPBUTT.DEF")),
|
||||
bRandom(genRect(0,0,414,105),boost::bind(&CPreGame::showScenList,CPG),CDefHandler::giveDef("GSPBUTT.DEF")),
|
||||
bOptions(genRect(0,0,414,509),boost::bind(&CPreGame::showOptions,CPG),CDefHandler::giveDef("GSPBUTT.DEF"))
|
||||
|
@ -221,7 +221,7 @@ public:
|
||||
//RanSel ransel;
|
||||
MapSel mapsel;
|
||||
SDL_Surface * background, *scenInf, *scenList, *randMap, *options ;
|
||||
Button bScens, bOptions, bRandom, bBegin, bBack;
|
||||
Button bScens, bOptions, bRandom, bBegin, bLoad, bBack;
|
||||
IntSelBut bEasy, bNormal, bHard, bExpert, bImpossible;
|
||||
Button * pressed;
|
||||
std::vector<Mapa> maps;
|
||||
|
@ -32,12 +32,14 @@ SharedMem sm;
|
||||
|
||||
CClient::CClient(void)
|
||||
{
|
||||
IObjectInterface::cb = this;
|
||||
serv = NULL;
|
||||
gs = NULL;
|
||||
cb = NULL;
|
||||
}
|
||||
CClient::CClient(CConnection *con, StartInfo *si)
|
||||
{
|
||||
IObjectInterface::cb = this;
|
||||
newGame(con,si);
|
||||
}
|
||||
CClient::~CClient(void)
|
||||
@ -703,7 +705,6 @@ int CClient::getSelectedHero()
|
||||
void CClient::newGame( CConnection *con, StartInfo *si )
|
||||
{
|
||||
timeHandler tmh;
|
||||
IObjectInterface::cb = this;
|
||||
CGI->state = new CGameState();
|
||||
tlog0 <<"\tGamestate: "<<tmh.getDif()<<std::endl;
|
||||
serv = con;
|
||||
|
@ -12,7 +12,7 @@ CArtHandler::CArtHandler()
|
||||
{
|
||||
VLC->arth = this;
|
||||
}
|
||||
void CArtHandler::loadArtifacts()
|
||||
void CArtHandler::loadArtifacts(bool onlyTxt)
|
||||
{
|
||||
std::vector<ui16> slots;
|
||||
slots += 17, 16, 15,14,13, 18, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0;
|
||||
@ -42,6 +42,7 @@ void CArtHandler::loadArtifacts()
|
||||
nart.aClass = classes[pom[0]];
|
||||
loadToIt(VLC->generaltexth->artifDescriptions[i],buf,it,3);
|
||||
nart.id=i;
|
||||
if(!onlyTxt)
|
||||
artifacts.push_back(nart);
|
||||
}
|
||||
sortArts();
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
std::vector<CArtifact*> treasures, minors, majors, relics;
|
||||
std::vector<CArtifact> artifacts;
|
||||
|
||||
void loadArtifacts();
|
||||
void loadArtifacts(bool onlyTxt);
|
||||
void sortArts();
|
||||
static int convertMachineID(int id, bool creToArt);
|
||||
CArtHandler();
|
||||
|
@ -1088,7 +1088,7 @@ void CGResource::onHeroVisit( const CGHeroInstance * h ) const
|
||||
}
|
||||
else
|
||||
{
|
||||
fightForRes(1,h);
|
||||
fightForRes(0,h);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1116,9 +1116,9 @@ void CGResource::collectRes( int player ) const
|
||||
cb->removeObject(id);
|
||||
}
|
||||
|
||||
void CGResource::fightForRes(ui32 wantToFight, const CGHeroInstance *h) const
|
||||
void CGResource::fightForRes(ui32 refusedFight, const CGHeroInstance *h) const
|
||||
{
|
||||
if(wantToFight)
|
||||
if(refusedFight)
|
||||
return;
|
||||
|
||||
cb->startBattleI(h->id,army,pos,boost::bind(&CGResource::endBattle,this,_1,h));
|
||||
|
@ -464,7 +464,7 @@ public:
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
void collectRes(int player) const;
|
||||
void initObj();
|
||||
void fightForRes(ui32 wantToFight, const CGHeroInstance *h) const;
|
||||
void fightForRes(ui32 refusedFight, const CGHeroInstance *h) const;
|
||||
void endBattle(BattleResult *result, const CGHeroInstance *h) const;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
|
@ -158,7 +158,7 @@ void LibClasses::init()
|
||||
tlog0 <<"\tHero handler: "<<pomtime.getDif()<<std::endl;
|
||||
|
||||
arth = new CArtHandler;
|
||||
arth->loadArtifacts();
|
||||
arth->loadArtifacts(false);
|
||||
tlog0<<"\tArtifact handler: "<<pomtime.getDif()<<std::endl;
|
||||
|
||||
creh = new CCreatureHandler();
|
||||
|
@ -39,12 +39,13 @@ public:
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & heroh & arth & creh & townh & objh & dobjinfo & buildh & spellh;
|
||||
if(!h.saving)
|
||||
{
|
||||
generaltexth = new CGeneralTextHandler;
|
||||
generaltexth->load();
|
||||
arth->loadArtifacts(true);
|
||||
}
|
||||
h & heroh & arth & creh & townh & objh & dobjinfo & buildh & spellh;
|
||||
}
|
||||
};
|
||||
|
||||
|
2
map.h
2
map.h
@ -226,6 +226,7 @@ class DLL_EXPORT CMapInfo : public CMapHeader
|
||||
{
|
||||
public:
|
||||
std::string filename;
|
||||
std::string date;
|
||||
int playerAmnt, humenPlayers;
|
||||
CMapInfo(){};
|
||||
void countPlayers();
|
||||
@ -409,6 +410,7 @@ struct DLL_EXPORT Mapa : public CMapHeader
|
||||
case 26: //for event objects
|
||||
SERIALIZE(CGEvent);
|
||||
break;
|
||||
case 4: //arena
|
||||
case 51: //Mercenary Camp
|
||||
case 23: //Marletto Tower
|
||||
case 61: // Star Axis
|
||||
|
@ -376,7 +376,11 @@ void CMapHandler::initObjectRects()
|
||||
cr.y = fy<<5; //fy*32
|
||||
std::pair<CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(map->objects[f],cr);
|
||||
|
||||
if((map->objects[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (map->objects[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (map->objects[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (map->objects[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
|
||||
if( (map->objects[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1) >= 0
|
||||
&& (map->objects[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1) < ttiles.size() - Woff
|
||||
&& (map->objects[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1) >= 0
|
||||
&& (map->objects[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1) < ttiles[0].size() - Hoff
|
||||
)
|
||||
{
|
||||
//TerrainTile2 & curt =
|
||||
// ttiles
|
||||
@ -474,14 +478,7 @@ void CMapHandler::init()
|
||||
}
|
||||
}
|
||||
|
||||
//for(int i=0; i<map->defy.size(); i++)
|
||||
//{
|
||||
// map->defy[i]->serial = i;
|
||||
// processDef(map->defy[i]);
|
||||
//}
|
||||
|
||||
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
|
||||
tlog0<<"\tUnpacking and handling defs: "<<th.getDif()<<std::endl;
|
||||
|
||||
for(int i=0;i<PLAYER_LIMIT;i++)
|
||||
@ -1550,6 +1547,17 @@ CMapHandler::~CMapHandler()
|
||||
{
|
||||
delete fullHide;
|
||||
delete partialHide;
|
||||
|
||||
for(int i=0; i < map->defy.size(); i++)
|
||||
delete map->defy[i];
|
||||
|
||||
for(int i=0; i < roadDefs.size(); i++)
|
||||
delete delete roadDefs[i];
|
||||
|
||||
for(int i=0; i < staticRiverDefs.size(); i++)
|
||||
delete delete staticRiverDefs[i];
|
||||
|
||||
//TODO: delete border graphics
|
||||
}
|
||||
|
||||
CMapHandler::CMapHandler()
|
||||
|
@ -1512,6 +1512,7 @@ void CGameHandler::moveStack(int stack, int dest)
|
||||
CGameHandler::CGameHandler(void)
|
||||
{
|
||||
gs = NULL;
|
||||
IObjectInterface::cb = this;
|
||||
}
|
||||
|
||||
CGameHandler::~CGameHandler(void)
|
||||
@ -1520,7 +1521,6 @@ CGameHandler::~CGameHandler(void)
|
||||
}
|
||||
void CGameHandler::init(StartInfo *si, int Seed)
|
||||
{
|
||||
IObjectInterface::cb = this;
|
||||
Mapa *map = new Mapa(si->mapname);
|
||||
tlog0 << "Map loaded!" << std::endl;
|
||||
gs = new CGameState();
|
||||
|
Loading…
Reference in New Issue
Block a user