mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
* CLodHandler now stories entries in nodrze (much faster searching)
* CLodHandler init cleared up (a bit) * giveDef optimized * horizontal slider * printAtMiddle updates corrrect rect * adjusted shadows * parts of advanced options menu * minor fixes/improvements
This commit is contained in:
parent
66ba3d0eab
commit
db65d9ee15
@ -142,6 +142,10 @@ void CHeroHandler::loadHeroes()
|
||||
delete[500] tab;
|
||||
}
|
||||
loadSpecialAbilities();
|
||||
|
||||
//for (int i=0;i<heroes.size();i++)
|
||||
//TODO: read portrait
|
||||
|
||||
}
|
||||
void CHeroHandler::loadSpecialAbilities()
|
||||
{
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "CCreatureHandler.h"
|
||||
#include "SDL.h"
|
||||
|
||||
class CHeroClass;
|
||||
|
||||
@ -22,6 +23,7 @@ public:
|
||||
CHeroClass * heroClass;
|
||||
EHeroClasses heroType; //hero class
|
||||
//bool operator<(CHero& drugi){if (ID < drugi.ID) return true; else return false;}
|
||||
SDL_Surface * portraitSmall; //48x32 p
|
||||
};
|
||||
|
||||
class CHeroClass
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "CLodHandler.h"
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
|
||||
|
||||
@ -382,11 +383,35 @@ int CLodHandler::infm(FILE *source, FILE *dest, int wBits)
|
||||
(void)inflateEnd(&strm);
|
||||
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
|
||||
}
|
||||
CDefHandler * CLodHandler::giveDef(std::string defName) // TODO: zamienic
|
||||
CDefHandler * CLodHandler::giveDef(std::string defName)
|
||||
{
|
||||
std::vector<std::string> pom;
|
||||
pom.push_back(defName);
|
||||
return extractManyFiles(pom)[0];
|
||||
Entry * ourEntry = entries.znajdz(Entry(defName));
|
||||
CDefHandler * ret;
|
||||
FLOD.seekg(ourEntry->offset,std::ios_base::beg);
|
||||
unsigned char * outp;
|
||||
if (ourEntry->size==0) //file is not compressed
|
||||
{
|
||||
outp = new unsigned char[ourEntry->realSize];
|
||||
FLOD.read((char*)outp, ourEntry->realSize);
|
||||
CDefHandler * nh = new CDefHandler;
|
||||
nh->openFromMemory(outp, ourEntry->realSize, std::string((char*)ourEntry->name));
|
||||
nh->alphaTransformed = false;
|
||||
ret = nh;
|
||||
}
|
||||
else //we will decompressing file
|
||||
{
|
||||
outp = new unsigned char[ourEntry->size];
|
||||
FLOD.read((char*)outp, ourEntry->size);
|
||||
FLOD.seekg(0, std::ios_base::beg);
|
||||
unsigned char * decomp = NULL;
|
||||
int decRes = infs2(outp, ourEntry->size, ourEntry->realSize, decomp);
|
||||
CDefHandler * nh = new CDefHandler;
|
||||
nh->openFromMemory(decomp, ourEntry->realSize, std::string((char*)ourEntry->name));
|
||||
nh->alphaTransformed = false;
|
||||
ret = nh;
|
||||
}
|
||||
delete outp;
|
||||
return ret;
|
||||
}
|
||||
std::vector<CDefHandler *> CLodHandler::extractManyFiles(std::vector<std::string> defNamesIn)
|
||||
{
|
||||
@ -794,22 +819,16 @@ int CLodHandler::readNormalNr (unsigned char* bufor, int bytCon, bool cyclic)
|
||||
|
||||
void CLodHandler::init(std::string lodFile)
|
||||
{
|
||||
FLOD;
|
||||
std::string Ts;
|
||||
//std::cout<<"*** Loading FAT ... \n";
|
||||
FLOD.open(lodFile.c_str(),std::ios::binary);
|
||||
//std::cout<<"*** Archive: "+FName+" loaded\n";
|
||||
FLOD.seekg(8,std::ios_base::beg);
|
||||
unsigned char temp[4];
|
||||
FLOD.read((char*)temp,4);
|
||||
totalFiles = readNormalNr(temp,4);
|
||||
FLOD.seekg(0x5c,std::ios_base::beg);
|
||||
entries.reserve(totalFiles);
|
||||
//std::cout<<"*** Loading FAT ...\n";
|
||||
for (int i=0; i<totalFiles; i++)
|
||||
{
|
||||
entries.push_back(Entry());
|
||||
//FLOD.read((char*)entries[i].name,12);
|
||||
Entry entry;
|
||||
char * bufc = new char;
|
||||
bool appending = true;
|
||||
for(int kk=0; kk<12; ++kk)
|
||||
@ -817,23 +836,30 @@ void CLodHandler::init(std::string lodFile)
|
||||
FLOD.read(bufc, 1);
|
||||
if(appending)
|
||||
{
|
||||
entries[i].name[kk] = toupper(*bufc);
|
||||
entry.name[kk] = toupper(*bufc);
|
||||
}
|
||||
else
|
||||
{
|
||||
entries[i].name[kk] = 0;
|
||||
entry.name[kk] = 0;
|
||||
appending = false;
|
||||
}
|
||||
}
|
||||
delete bufc;
|
||||
FLOD.read((char*)entries[i].hlam_1,4);
|
||||
FLOD.read((char*)entry.hlam_1,4);
|
||||
FLOD.read((char*)temp,4);
|
||||
entries[i].offset=readNormalNr(temp,4);
|
||||
entry.offset=readNormalNr(temp,4);
|
||||
FLOD.read((char*)temp,4);
|
||||
entries[i].realSize=readNormalNr(temp,4);
|
||||
FLOD.read((char*)entries[i].hlam_2,4);
|
||||
entry.realSize=readNormalNr(temp,4);
|
||||
FLOD.read((char*)entry.hlam_2,4);
|
||||
FLOD.read((char*)temp,4);
|
||||
entries[i].size=readNormalNr(temp,4);
|
||||
entry.size=readNormalNr(temp,4);
|
||||
for (int z=0;z<12;z++)
|
||||
{
|
||||
if (entry.name[z])
|
||||
entry.nameStr+=entry.name[z];
|
||||
else break;
|
||||
}
|
||||
entries.push_back(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
#include "zlib.h"
|
||||
#include "CDefHandler.h"
|
||||
#include "nodrze.h"
|
||||
|
||||
enum Epcxformat {PCX8B, PCX24B};
|
||||
|
||||
@ -28,9 +29,10 @@ struct Entry
|
||||
size; //and with
|
||||
bool operator<(const Entry & comp) const
|
||||
{
|
||||
return this->nameStr<comp.nameStr;
|
||||
return nameStr<comp.nameStr;
|
||||
}
|
||||
Entry(std::string con): nameStr(con){};
|
||||
//Entry(unsigned char ): nameStr(con){};
|
||||
Entry(){};
|
||||
};
|
||||
class CPCXConv
|
||||
@ -52,7 +54,7 @@ class CLodHandler
|
||||
private:
|
||||
std::ifstream FLOD;
|
||||
public:
|
||||
std::vector<Entry> entries;
|
||||
nodrze<Entry> entries;
|
||||
unsigned int totalFiles;
|
||||
|
||||
int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper
|
||||
|
14
CMessage.h
14
CMessage.h
@ -41,10 +41,12 @@ template <class T=ttt> struct SetrButton: public Button<T>
|
||||
template<class T=CPreGame> class Slider
|
||||
{ //
|
||||
public:
|
||||
SDL_Rect pos;
|
||||
Button<void(Slider::*)()> up, down, slider;
|
||||
int positionsAmnt, capacity;
|
||||
int whereAreWe;
|
||||
bool vertical; // false means horizontal
|
||||
SDL_Rect pos; // position
|
||||
Button<void(Slider::*)()> up, down, //or left/right
|
||||
slider;
|
||||
int positionsAmnt, capacity;// capacity - amount of positions dispplayed at once
|
||||
int whereAreWe; // first displayed thing
|
||||
bool moving;
|
||||
void(T::*fun)(int);
|
||||
void clickDown(int x, int y, bool bzgl=true);
|
||||
@ -52,8 +54,8 @@ public:
|
||||
void mMove(int x, int y, bool bzgl=true);
|
||||
void moveUp();
|
||||
void moveDown();
|
||||
void activate(MapSel * ms);
|
||||
Slider(int x, int y, int h, int amnt, int cap);
|
||||
void activate();
|
||||
Slider(int x, int y, int h, int amnt, int cap, bool ver);
|
||||
void updateSlid();
|
||||
void handleIt(SDL_Event sev);
|
||||
|
||||
|
BIN
CPreGame.cpp
BIN
CPreGame.cpp
Binary file not shown.
45
CPreGame.h
45
CPreGame.h
@ -1,6 +1,5 @@
|
||||
#ifndef CPREGAME_H
|
||||
#define CPREGAME_H
|
||||
|
||||
#include "SDL.h"
|
||||
#include "CSemiDefHandler.h"
|
||||
#include "CSemiLodHandler.h"
|
||||
@ -10,13 +9,47 @@
|
||||
#include "CMusicHandler.h"
|
||||
class CPreGame;
|
||||
extern CPreGame * CPG;
|
||||
struct RanSel
|
||||
enum Ebonus {brandom=-1,bartifact, bgold, bresource};
|
||||
struct StartInfo
|
||||
{
|
||||
struct PlayerSettings
|
||||
{
|
||||
int castle, hero; //ID, if -1 then random, if -2 then none
|
||||
Ebonus bonus;
|
||||
Ecolor color; //from 0 -
|
||||
int handicap;//0-no, 1-mild, 2-severe
|
||||
std::string name;
|
||||
};
|
||||
std::vector<PlayerSettings> playerInfos;
|
||||
int turnTime; //in minutes, 0=unlimited
|
||||
};
|
||||
class RanSel
|
||||
{
|
||||
Button<> horcpl[9], horcte[9], conpl[9], conte[8], water[4], monster[4], //last is random
|
||||
size[4], twoLevel, showRand;
|
||||
CGroup<> *Ghorcpl, *Ghorcte, *Gconpl, *Gconte, *Gwater, *Gmonster, *Gsize;
|
||||
};
|
||||
|
||||
class Options
|
||||
{
|
||||
struct PlayerOptions
|
||||
{
|
||||
Ecolor color;
|
||||
//SDL_Surface * bg;
|
||||
Button<> left, right;
|
||||
int nr;
|
||||
};
|
||||
public:
|
||||
Slider<> * turnLength;
|
||||
SDL_Surface * bg;
|
||||
std::vector<SDL_Surface*> bgs;
|
||||
CDefHandler //* castles, * heroes, * bonus,
|
||||
* left, * right;
|
||||
std::vector<PlayerOptions> poptions;
|
||||
void show();
|
||||
void init();
|
||||
//Options();
|
||||
~Options();
|
||||
};
|
||||
class MapSel
|
||||
{
|
||||
public:
|
||||
@ -68,6 +101,7 @@ public:
|
||||
class CPreGame
|
||||
{
|
||||
public:
|
||||
StartInfo ret;
|
||||
bool run;
|
||||
std::vector<Slider<> *> interested;
|
||||
CMusicHandler * mush;
|
||||
@ -88,6 +122,7 @@ public:
|
||||
int highlighted;//0=none; 1=new game; 2=load game; 3=high score; 4=credits; 5=quit
|
||||
} * ourMainMenu, * ourNewMenu;
|
||||
ScenSel * ourScenSel;
|
||||
Options * ourOptions;
|
||||
std::string map; //selected map
|
||||
std::vector<CSemiLodHandler *> handledLods;
|
||||
CPreGame(); //c-tor
|
||||
@ -101,17 +136,19 @@ public:
|
||||
void initScenSel();
|
||||
void showScenSel();
|
||||
void showScenList();
|
||||
void initOptions();
|
||||
void showOptions();
|
||||
void initNewMenu();
|
||||
void showNewMenu();
|
||||
void showMainMenu();
|
||||
void runLoop(); // runs mainloop of PreGame
|
||||
StartInfo runLoop(); // runs mainloop of PreGame
|
||||
void initMainMenu(); //loads components for main menu
|
||||
void highlightButton(int which, int on); //highlights one from 5 main menu buttons
|
||||
void showCenBox (std::string data); //
|
||||
void showAskBox (std::string data, void(*f1)(),void(*f2)());
|
||||
void hideBox ();
|
||||
void printMapsFrom(int from);
|
||||
void setTurnLength(int on);
|
||||
void sortMaps();
|
||||
};
|
||||
|
||||
|
@ -63,7 +63,7 @@ void CSDL_Ext::printAtMiddle(std::string text, int x, int y, TTF_Font * font, SD
|
||||
break;
|
||||
}
|
||||
SDL_BlitSurface(temp,NULL,dst,&genRect(temp->h,temp->w,x-(temp->w/2),y-(temp->h/2)));
|
||||
SDL_UpdateRect(dst,x,y,temp->w,temp->h);
|
||||
SDL_UpdateRect(dst,x-(temp->w/2),y-(temp->h/2),temp->w,temp->h);
|
||||
SDL_FreeSurface(temp);
|
||||
}
|
||||
void CSDL_Ext::printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality)
|
||||
@ -359,7 +359,7 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src)
|
||||
switch(cur.g) //change this values; make diffrerent for objects and shadows (?)
|
||||
{
|
||||
case 0:
|
||||
shadow.unused = 0+32;
|
||||
shadow.unused = 128;
|
||||
break;
|
||||
case 50:
|
||||
shadow.unused = 50+32;
|
||||
|
@ -6,7 +6,7 @@
|
||||
LGPL (c) A. Schiffler
|
||||
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "SDL_framerate.h"
|
||||
|
||||
/*
|
4
global.h
4
global.h
@ -8,6 +8,7 @@
|
||||
#else
|
||||
#define THC //
|
||||
#endif
|
||||
enum Ecolor {RED, BLUE, TAN, GREEN, ORANGE, PURPLE, TEAL, PINK};
|
||||
enum EterrainType {dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock};
|
||||
enum Eriver {clearRiver=1, icyRiver, muddyRiver, lavaRiver};
|
||||
enum Eroad {dirtRoad=1, grazvelRoad, cobblestoneRoad};
|
||||
@ -16,5 +17,8 @@ enum EvictoryConditions {artifact, gatherTroop, gatherResource, buildCity, build
|
||||
captureCity, beatMonster, takeDwellings, takeMines, transportItem, winStandard=255};
|
||||
enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=255};
|
||||
|
||||
const int F_NUMBER = 9; //factions quantity
|
||||
const int PLAYER_LIMIT = 8; //player limit per map
|
||||
|
||||
#define DEFBYPASS
|
||||
#endif //GLOBAL_H
|
12
map.cpp
12
map.cpp
@ -49,17 +49,17 @@ CMapHeader::CMapHeader(unsigned char *map)
|
||||
}
|
||||
|
||||
this->players[pom].AITactic = map[i++];
|
||||
if (map[i++])
|
||||
/*if (map[i++])*/i++;
|
||||
{
|
||||
this->players[pom].allowedFactions = 0;
|
||||
this->players[pom].allowedFactions += map[i++];
|
||||
this->players[pom].allowedFactions += (map[i++])*256;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->players[pom].allowedFactions = 511;
|
||||
i+=2;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// this->players[pom].allowedFactions = 511;
|
||||
// i+=2;
|
||||
//}
|
||||
this->players[pom].isFactionRandom = map[i++];
|
||||
this->players[pom].hasMainTown = map[i++];
|
||||
if (this->players[pom].hasMainTown)
|
||||
|
2
map.h
2
map.h
@ -218,7 +218,7 @@ public:
|
||||
CMapInfo(std::string fname, unsigned char *map):CMapHeader(map),filename(fname)
|
||||
{
|
||||
playerAmnt=humenPlayers=0;
|
||||
for (int i=0;i<8;i++)
|
||||
for (int i=0;i<PLAYER_LIMIT;i++)
|
||||
{
|
||||
if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
|
||||
else if (players[i].canComputerPlay) {playerAmnt++;}
|
||||
|
51
nodrze.h
51
nodrze.h
@ -81,42 +81,59 @@ private:
|
||||
void wypisuj(wezel<T> * w, std::ostream & strum);
|
||||
void wypisujPre(wezel<T> * w, std::ostream & strum);
|
||||
public:
|
||||
wezel<T> * korzen;
|
||||
nodrze():ile(0) //najzwyczajniejszy w swiecie kosntruktor
|
||||
wezel<T> * korzen; //root
|
||||
nodrze():ile(0) //najzwyczajniejszy w swiecie kosntruktor // c-tor
|
||||
{
|
||||
NIL=new wezel<T>(CZARNY);
|
||||
korzen=NIL;
|
||||
ostatnio=NIL;
|
||||
ktory=0;
|
||||
};
|
||||
T * begin () {return minimumimum();};
|
||||
T * end () {return NIL;};
|
||||
T * begin () {return minimumimum();}; //first element (=minimum)
|
||||
T * end () {return NIL;}; //
|
||||
void clear(); // czysci az do korzenia wlacznie
|
||||
// removes all elements, including root
|
||||
void usun (T co); // usuwa element z drzewa
|
||||
// remove element (value)
|
||||
bool sprawdz(); // sprawdza, czy drzewo jest poprawnym drzewem BST
|
||||
T * nast(T czego); // nastepnik zadenego elementu
|
||||
//checks if tree is correct (rather useful only for debugging)
|
||||
T * nast(T czego); // nastepnik zadanego elementu
|
||||
// successor of that element
|
||||
T * maksimumimum (); // najwiekszy element w drzewie
|
||||
//biggest element (and last)
|
||||
bool czyJest(T co); // czy cos jest w drzewie
|
||||
//check if given element is in tree
|
||||
T * minimumimum (); // najmniejszy element w drzewie
|
||||
//smallest element (first)
|
||||
void dodaj (T co); // dodaje element do drzewa
|
||||
// adds (copies)
|
||||
void inorder(std::ostream & strum); // wypisuje na zadane wyjscie elementy w porzadku inorder
|
||||
//print all elements inorder
|
||||
void preorder(std::ostream & strum); // wypisuje na zadane wyjscie elementy w porzadku preorder
|
||||
//print all elements preorder
|
||||
void postorder(std::ostream & strum); // wypisuje na zadane wyjscie elementy w porzadku postorder
|
||||
//print all elements postorder
|
||||
void wypiszObficie(std::ostream & strum); //wypisuje dane o kazdym wezle -- wymaga operatora >> dla zawartosci
|
||||
//prints info about all nodes - >> operator for T needed
|
||||
T * znajdz (T co, bool iter = true); // wyszukuje zadany element
|
||||
//search for T
|
||||
int size(); //ilosc elementow
|
||||
//returns size of tree
|
||||
T* operator()(int i) ; //n-ty element przez wskaxnik
|
||||
//returns pointer to element with index i
|
||||
nodrze<T> & operator()(std::istream & potoczek) ; //zczytanie n elemntow z listy
|
||||
//read elements from istream (first must be given amount of elements)
|
||||
T& operator[](int i) ; //dostep do obiektu, ale przez wartosc
|
||||
bool operator+=(T * co);
|
||||
bool operator+=(T co);
|
||||
bool operator-=(T co);
|
||||
bool operator-=(T * co);
|
||||
T* operator%(T * co);
|
||||
bool operator&(T co);
|
||||
bool operator&(T * co);
|
||||
template <typename Y, class X> friend Y* operator%(nodrze<Y> & drzewko, X co);
|
||||
void push_back(T co){(*this)+=co;};
|
||||
//returns value of object with index i
|
||||
bool operator+=(T * co); //add
|
||||
bool operator+=(T co); //add
|
||||
bool operator-=(T co); //remove
|
||||
bool operator-=(T * co); //remove
|
||||
T* operator%(T * co); // search and return pointer
|
||||
bool operator&(T co); // check if exist
|
||||
bool operator&(T * co); // check if exist
|
||||
template <typename Y, class X> friend Y* operator%(nodrze<Y> & drzewko, X co); // search and return pointer
|
||||
void push_back(T co){(*this)+=co;}; // add
|
||||
};
|
||||
template <typename T> void nodrze<T>::wypisuj(wezel<T> * w, std::ostream & strum)
|
||||
{
|
||||
@ -774,7 +791,7 @@ template <typename T> bool nodrze<T>::czyJest(T co)
|
||||
}
|
||||
template <typename T> wezel<T> * nodrze<T>::szukajRek(wezel<T> * w, T co)
|
||||
{
|
||||
if (w==NIL || (*w->zawart)==co)
|
||||
if (w==NIL || (!(((*w->zawart)<co)||(co<(*w->zawart)))))
|
||||
return w;
|
||||
if (co < (*w->zawart))
|
||||
return szukajRek(w->lewy,co);
|
||||
@ -782,13 +799,13 @@ template <typename T> wezel<T> * nodrze<T>::szukajRek(wezel<T> * w, T co)
|
||||
};
|
||||
template <typename T> wezel<T> * nodrze<T>::szukajIter(wezel<T> * w, T co)
|
||||
{
|
||||
while (w!=NIL && (*w->zawart)!=co)
|
||||
while ( w!=NIL && (((*w->zawart)<co)||(co<(*w->zawart))) )
|
||||
{
|
||||
if (co < (*w->zawart))
|
||||
w=w->lewy;
|
||||
else w=w->prawy;
|
||||
}
|
||||
return w;
|
||||
return (w)?w:NULL;
|
||||
};
|
||||
template <typename T> wezel<T> * nodrze<T>::minimum(wezel<T> * w)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user