1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00

Na początek.

This commit is contained in:
Michał W. Urbańczyk 2007-06-06 16:12:12 +00:00
parent ac4ce5af49
commit 01e84b9e40
13 changed files with 2187 additions and 0 deletions

337
CAmbarCendamo.cpp Normal file
View File

@ -0,0 +1,337 @@
#include "stdafx.h"
#include "CAmbarCendamo.h"
#include "CSemiDefHandler.h"
#include <fstream>
#include <set>
CAmbarCendamo::CAmbarCendamo (const char * tie)
{
is = new std::ifstream();
is -> open(tie,std::ios::binary);
is->seekg(0,std::ios::end); // na koniec
andame = is->tellg(); // read length
is->seekg(0,std::ios::beg); // wracamy na poczatek
bufor = new unsigned char[andame]; // allocate memory
is->read((char*)bufor, andame); // read map file to buffer
}
CAmbarCendamo::~CAmbarCendamo ()
{// free memory
for (int ii=0;ii<map.width;ii++)
delete map.terrain[ii] ;
delete map.terrain;
delete bufor;
}
void CAmbarCendamo::teceDef()
{
for (int i=0; i<map.defy.size(); i++)
{
std::ofstream * of = new std::ofstream(map.defy[i].name.c_str());
for (int j=0;j<46;j++)
{
(*of) << map.defy[i].bytes[j]<<std::endl;
}
delete of;
}
}
void CAmbarCendamo::deh3m()
{
map.version = (Eformat)bufor[0]; //wersja mapy
map.areAnyPLayers = bufor[4];
map.height = map.width = bufor[5]; // wymiary mapy
map.twoLevel = bufor[9]; //czy sa lochy
map.terrain = new TerrainTile*[map.width]; // allocate memory
for (int ii=0;ii<map.width;ii++)
map.terrain[ii] = new TerrainTile[map.height]; // allocate memory
if (map.twoLevel)
{
map.undergroungTerrain = new TerrainTile*[map.width]; // allocate memory
for (int ii=0;ii<map.width;ii++)
map.undergroungTerrain[ii] = new TerrainTile[map.height]; // allocate memory
}
int length = bufor[10]; //name length
int i=14, pom;
while (i-14<length) //read name
map.name+=bufor[i++];
length = bufor[i] + bufor[i+1]*256; //description length
i+=4;
for (pom=0;pom<length;pom++)
map.description+=bufor[i++];
map.difficulty = bufor[i++]; // reading map difficulty
map.levelLimit = bufor[i++]; // hero level limit
for (pom=0;pom<8;pom++)
{
map.players[pom].canHumanPlay = bufor[i++];
map.players[pom].canComputerPlay = bufor[i++];
if (!(map.players[pom].canHumanPlay || map.players[pom].canComputerPlay))
{
i+=13;
continue;
}
map.players[pom].AITactic = bufor[i++];
if (bufor[i++])
{
map.players[pom].allowedFactions = 0;
map.players[pom].allowedFactions += bufor[i++];
map.players[pom].allowedFactions += (bufor[i++])*256;
}
else
{
map.players[pom].allowedFactions = 511;
i+=2;
}
map.players[pom].isFactionRandom = bufor[i++];
i+=2; //unknown bytes
int unknown = bufor[i++];
if (unknown == 255)
{
map.players[pom].mainHeroPortrait = 255;
i+=5;
continue;
}
map.players[pom].mainHeroPortrait = bufor[i++];
int nameLength = bufor[i++];
i+=3;
for (int pp=0;pp<nameLength;pp++)
map.players[pom].mainHeroName+=bufor[i++];
i++; ////unknown byte
int heroCount = bufor[i++];
i+=3;
for (int pp=0;pp<heroCount;pp++)
{
SheroName vv;
vv.heroID=bufor[i++];
int hnl = bufor[i++];
i+=3;
for (int zz=0;zz<hnl;zz++)
{
vv.heroName+=bufor[i++];
}
map.players[pom].heroesNames.push_back(vv);
}
}
map.victoryCondition = (EvictoryConditions)bufor[i++];
if (map.victoryCondition != winStandard) //specific victory conditions
{
int nr;
switch (map.victoryCondition) //read victory conditions
{
case artifact:
{
map.vicConDetails = new VicCon0();
((VicCon0*)map.vicConDetails)->ArtifactID = bufor[i+2];
nr=2;
break;
}
case gatherTroop:
{
map.vicConDetails = new VicCon1();
int temp1 = bufor[i+2];
int temp2 = bufor[i+3];
((VicCon1*)map.vicConDetails)->monsterID = bufor[i+2];
((VicCon1*)map.vicConDetails)->neededQuantity=readNormalNr(i+4);
nr=6;
break;
}
case gatherResource:
{
map.vicConDetails = new VicCon2();
((VicCon2*)map.vicConDetails)->resourceID = bufor[i+2];
((VicCon2*)map.vicConDetails)->neededQuantity=readNormalNr(i+3);
nr=5;
break;
}
case buildCity:
{
map.vicConDetails = new VicCon3();
((VicCon3*)map.vicConDetails)->posOfCity.x = bufor[i+2];
((VicCon3*)map.vicConDetails)->posOfCity.y = bufor[i+3];
((VicCon3*)map.vicConDetails)->posOfCity.z = bufor[i+4];
((VicCon3*)map.vicConDetails)->councilNeededLevel = bufor[i+5];
((VicCon3*)map.vicConDetails)->fortNeededLevel = bufor[i+6];
nr=5;
break;
}
case buildGrail:
{
map.vicConDetails = new VicCon4();
if (bufor[i+4]>2)
((VicCon4*)map.vicConDetails)->anyLocation = true;
else
{
((VicCon4*)map.vicConDetails)->whereBuildGrail.x = bufor[i+2];
((VicCon4*)map.vicConDetails)->whereBuildGrail.y = bufor[i+3];
((VicCon4*)map.vicConDetails)->whereBuildGrail.z = bufor[i+4];
}
nr=3;
break;
}
case beatHero:
{
map.vicConDetails = new VicCon5();
((VicCon5*)map.vicConDetails)->locationOfHero.x = bufor[i+2];
((VicCon5*)map.vicConDetails)->locationOfHero.y = bufor[i+3];
((VicCon5*)map.vicConDetails)->locationOfHero.z = bufor[i+4];
nr=3;
break;
}
case captureCity:
{
map.vicConDetails = new VicCon6();
((VicCon6*)map.vicConDetails)->locationOfTown.x = bufor[i+2];
((VicCon6*)map.vicConDetails)->locationOfTown.y = bufor[i+3];
((VicCon6*)map.vicConDetails)->locationOfTown.z = bufor[i+4];
nr=3;
break;
}
case beatMonster:
{
map.vicConDetails = new VicCon7();
((VicCon7*)map.vicConDetails)->locationOfMonster.x = bufor[i+2];
((VicCon7*)map.vicConDetails)->locationOfMonster.y = bufor[i+3];
((VicCon7*)map.vicConDetails)->locationOfMonster.z = bufor[i+4];
nr=3;
break;
}
case takeDwellings:
{
map.vicConDetails = new CspecificVictoryConidtions();
nr=3;
break;
}
case takeMines:
{
map.vicConDetails = new CspecificVictoryConidtions();
nr=3;
break;
}
case transportItem:
{
map.vicConDetails = new VicCona();
((VicCona*)map.vicConDetails)->artifactID = bufor[i+2];
((VicCona*)map.vicConDetails)->destinationPlace.x = bufor[i+3];
((VicCona*)map.vicConDetails)->destinationPlace.y = bufor[i+4];
((VicCona*)map.vicConDetails)->destinationPlace.z = bufor[i+5];
nr=3;
break;
}
}
map.vicConDetails->allowNormalVictory = bufor[i++];
map.vicConDetails->appliesToAI = bufor[i++];
i+=nr;
}
map.lossCondition.typeOfLossCon = (ElossCon)bufor[i++];
switch (map.lossCondition.typeOfLossCon) //read loss conditions
{
case lossCastle:
{
map.lossCondition.castlePos.x=bufor[i++];
map.lossCondition.castlePos.y=bufor[i++];
map.lossCondition.castlePos.z=bufor[i++];
}
case lossHero:
{
map.lossCondition.heroPos.x=bufor[i++];
map.lossCondition.heroPos.y=bufor[i++];
map.lossCondition.heroPos.z=bufor[i++];
}
case timeExpires:
{
map.lossCondition.timeLimit = readNormalNr(i++,2);
}
}
i+=88;
int rumNr = readNormalNr(i,4);i+=4;
for (int it=0;it<rumNr;it++)
{
Rumor ourRumor;
int nameL = readNormalNr(i,4);i+=4; //read length of name of rumor
for (int zz=0; zz<nameL; zz++)
ourRumor.name+=bufor[i++];
nameL = readNormalNr(i,4);i+=4; //read length of rumor
for (int zz=0; zz<nameL; zz++)
ourRumor.text+=bufor[i++];
map.rumors.push_back(ourRumor); //add to our list
}
i+=156;
for (int c=0; c<map.width; c++) // reading terrain
{
for (int z=0; z<map.height; z++)
{
map.terrain[z][c].tertype = (EterrainType)(bufor[i++]);
map.terrain[z][c].terview = bufor[i++];
map.terrain[z][c].nuine = (Eriver)bufor[i++];
map.terrain[z][c].rivDir = bufor[i++];
map.terrain[z][c].malle = (Eroad)bufor[i++];
map.terrain[z][c].roadDir = bufor[i++];
map.terrain[z][c].siodmyTajemniczyBajt = bufor[i++];
}
}
if (map.twoLevel) // read underground terrain
{
for (int z=0; z<map.width; z++) // reading terrain
{
for (int c=0; c<map.height; c++)
{
map.undergroungTerrain[z][c].tertype = (EterrainType)(bufor[i++]);
map.undergroungTerrain[z][c].terview = bufor[i++];
map.undergroungTerrain[z][c].nuine = (Eriver)bufor[i++];
map.undergroungTerrain[z][c].rivDir = bufor[i++];
map.undergroungTerrain[z][c].malle = (Eroad)bufor[i++];
map.undergroungTerrain[z][c].roadDir = bufor[i++];
map.undergroungTerrain[z][c].siodmyTajemniczyBajt = bufor[i++];
}
}
}
int defAmount = bufor[i]; // liczba defow
i+=8;
for (int idd = 0 ; idd<defAmount; idd++) // reading defs
{
DefInfo vinya; // info about new def
while (1) // read name
{
if (bufor[i] == '.' && bufor[i+1] == 'd' && bufor[i+2] == 'e' && bufor[i+3] == 'f')
{
vinya.name += ".def";
i+=4;
break;
}
vinya.name += bufor[i++];
}
for (int v=0; v<46; v++) // read info
{
vinya.bytes[v] = bufor[i++];
}
map.defy.push_back(vinya); // add this def to the vector
teceDef();
}
//todo: read events
}
int CAmbarCendamo::readNormalNr (int pos, int bytCon)
{
int ret=0;
int amp=1;
for (int i=0; i<bytCon; i++)
{
ret+=bufor[pos+i]*amp;
amp*=256;
}
return ret;
}
void CAmbarCendamo::loadDefs()
{
std::set<int> loadedTypes;
for (int i=0; i<map.width; i++)
{
for (int j=0; j<map.width; j++)
{
if (loadedTypes.find(map.terrain[i][j].tertype)==loadedTypes.end())
{
CSemiDefHandler *sdh = new CSemiDefHandler();
sdh->openDef(("H3sprite.lod\\"+sdh->nameFromType(map.terrain[i][j].tertype)).c_str());
loadedTypes.insert(map.terrain[i][j].tertype);
defs.push_back(sdh);
}
}
}
};

29
CAmbarCendamo.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef AMBARCENDD
#define AMBARCENDD
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "global.h"
#include "SDL.h"
#include "map.h"
#include "CSemiDefHandler.h"
class CAmbarCendamo
{
public:
/////////////////zmienne skladowe
Mapa map;
std::ifstream * is; // stream used to read map file
int andame; // length of map file
unsigned char * bufor; // here we store map bytecode
std::vector<CSemiDefHandler*> defs;
/////////////////funkcje skladowe
CAmbarCendamo (const char * tie); // c-tor; tie is the path of the map file
~CAmbarCendamo (); // d-tor
int readNormalNr (int pos, int bytCon=4); //read number from bytCon bytes starting from pos position in buffer
void teceDef (); // create files with info about defs
void deh3m(); // decode file, results are stored in map
void loadDefs();
};
#endif //AMBARCENDD

139
CSemiDefHandler.cpp Normal file
View File

@ -0,0 +1,139 @@
#include "stdafx.h"
#include "CSemiDefHandler.h"
#include <fstream>
extern SDL_Surface * ekran;
std::string CSemiDefHandler::nameFromType (EterrainType typ)
{
switch(typ)
{
case dirt:
{
return std::string("DIRTTL.DEF");
break;
}
case sand:
{
return std::string("SANDTL.DEF");
break;
}
case grass:
{
return std::string("GRASTL.DEF");
break;
}
case snow:
{
return std::string("SNOWTL.DEF");
break;
}
case swamp:
{
return std::string("SWMPTL.DEF");
break;
}
case rough:
{
return std::string("ROUGTL.DEF");
break;
}
case subterranean:
{
return std::string("SUBBTL.DEF");
break;
}
case lava:
{
return std::string("LAVATL.DEF");
break;
}
case water:
{
return std::string("WATRTL.DEF");
break;
}
case rock:
{
return std::string("ROCKTL.DEF");
break;
}
}
}
void CSemiDefHandler::openDef(const char *name)
{
std::ifstream * is = new std::ifstream();
is -> open(name,std::ios::binary);
is->seekg(0,std::ios::end); // na koniec
int andame = is->tellg(); // read length
is->seekg(0,std::ios::beg); // wracamy na poczatek
buforD = new unsigned char[andame]; // allocate memory
is->read((char*)buforD, andame); // read map file to buffer
defName = name;
int gdzie = defName.find_last_of("\\");
defName = defName.substr(gdzie+1, gdzie-defName.length());
delete is;
readFileList();
loadImages();
}
void CSemiDefHandler::readFileList()
{
howManyImgs = buforD[788];
int i = 800;
for (int pom=0;pom<howManyImgs;pom++)
{
std::string temp;
while (buforD[i]!=0)
{
temp+=buforD[i++];
}
i++;;
if (temp!="")
{
temp = temp.substr(0,temp.length()-4) + ".BMP";
namesOfImgs.push_back(temp);
}
else pom--;
}
}
void CSemiDefHandler::loadImages()
{
for (int i=0; i<namesOfImgs.size(); i++)
{
openImg(("H3sprite.lod\\_"+defName+"\\"+namesOfImgs[i]).c_str());
}
}
void SDL_DisplayBitmap(const char *file, SDL_Surface *ekran, int x, int y)
{
SDL_Surface *image;
SDL_Rect dest;
image = SDL_LoadBMP(file);
if ( image == NULL )
{
fprintf(stderr, "Nie mo¿na wczytaæ %s: %s\n", file, SDL_GetError());
return;
}
dest.x = x;
dest.y = y;
dest.w = image->w;
dest.h = image->h;
SDL_BlitSurface(image, NULL, ekran, &dest);
SDL_UpdateRects(ekran, 1, &dest);
SDL_FreeSurface(image);
}
void CSemiDefHandler::openImg(const char *name)
{
SDL_Surface *image;
image=IMG_Load(name);
//SDL_DisplayBitmap(name,image, 0,0);
if(!image)
{
printf("IMG_Load: %s\n", IMG_GetError());
// handle error
}
Cimage vinya;
vinya.bitmap=image;
vinya.imName = name;
ourImages.push_back(vinya);
}

28
CSemiDefHandler.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef SEMIDEF_H
#define SEMIDEF_H
#include "global.h"
#include <string>
#include "SDL.h"
#include "SDL_image.h"
#include <vector>
struct Cimage
{
std::string imName; //name without extension
SDL_Surface * bitmap;
};
class CSemiDefHandler
{
public:
int howManyImgs;
std::string defName;
std::vector<Cimage> ourImages;
std::vector<std::string> namesOfImgs;
unsigned char * buforD;
static std::string nameFromType(EterrainType typ);
void openImg(const char *name);
void openDef(const char *name);
void readFileList();
void loadImages();
};
#endif // SEMIDEF_H

1231
SDL_rotozoom.cpp Normal file

File diff suppressed because it is too large Load Diff

117
SDL_rotozoom.h Normal file
View File

@ -0,0 +1,117 @@
/*
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);
DLLINTERFACE 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 */
DLLINTERFACE void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth,
int *dstheight);
DLLINTERFACE 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.
*/
DLLINTERFACE SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth);
/* Returns the size of the target surface for a zoomSurface() call */
DLLINTERFACE 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.
*/
DLLINTERFACE SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* _SDL_rotozoom_h */

12
global.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef GLOBAL_H
#define GLOBAL_H
enum EterrainType {dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock};
enum Eriver {clearRiver=1, icyRiver, muddyRiver, lavaRiver};
enum Eroad {dirtRoad=1, gravelRoad, cobblestoneRoad};
enum Eformat { WoG=0x33, AB=0x15, RoE=0x0e, SoD=0x1c};
enum EvictoryConditions {artifact, gatherTroop, gatherResource, buildCity, buildGrail, beatHero,
captureCity, beatMonster, takeDwellings, takeMines, transportItem, winStandard=255};
enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=255};
#define DEFBYPASS
#endif //GLOBAL_H

47
inde.cpp Normal file
View File

@ -0,0 +1,47 @@
/* zpipe.c: example of proper use of zlib's inflate() and deflate()
Not copyrighted -- provided to the public domain
Version 1.4 11 December 2005 Mark Adler */
/* Version history:
1.0 30 Oct 2004 First version
1.1 8 Nov 2004 Add void casting for unused return values
Use switch statement for inflate() return values
1.2 9 Nov 2004 Add assertions to document zlib guarantees
1.3 6 Apr 2005 Remove incorrect assertion in inf()
1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions
Avoid some compiler warnings for input and output buffers
*/
#include "stdafx.h"
/* compress or decompress from stdin to stdout */
//int main(int argc, char **argv)
//{
// int ret;
//
// /* avoid end-of-line conversions */
// SET_BINARY_MODE(stdin);
// SET_BINARY_MODE(stdout);
//
// /* do compression if no arguments */
// if (argc == 1) {
// ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION);
// if (ret != Z_OK)
// zerr(ret);
// return ret;
// }
//
// /* do decompression if -d specified */
// else if (argc == 2 && strcmp(argv[1], "-d") == 0) {
// ret = inf(stdin, stdout);
// if (ret != Z_OK)
// zerr(ret);
// return ret;
// }
//
// /* otherwise, report usage */
// else {
// fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr);
// return 1;
// }
//}

147
map.h Normal file
View File

@ -0,0 +1,147 @@
#ifndef MAPD
#define MAPD
struct TimeEvent
{
//bajty wydarzeñ (59 + |teksty|)
//4 bajty na d³ugoœæ nazwy zdarzenia
//nazwa zdarzenia (bajty dodatkowe)
//4 bajty na d³ugoœæ wiadomoœci
//wiadomoϾ (bajty dodatkowe)
//4 bajty na zwiêkszenie siê ilosci drewna (zapis normalny) lub ff,ff,ff,ff - iloœæ drewna do odebrania (maksymalna iloœæ drewna, któr¹ mo¿na daæ/odebraæ to 32767)
//4 bajty na zwiêkszenie siê ilosci rtêci (zapis normalny) lub ff,ff,ff,ff - iloœæ rtêci do odebrania (maksymalna iloœæ rtêci, któr¹ mo¿na daæ/odebraæ to 32767)
//4 bajty na zwiêkszenie siê ilosci rudy (zapis normalny) lub ff,ff,ff,ff - iloœæ rudy do odebrania (maksymalna iloœæ rudy, któr¹ mo¿na daæ/odebraæ to 32767)
//4 bajty na zwiêkszenie siê ilosci siarki (zapis normalny) lub ff,ff,ff,ff - iloœæ siarki do odebrania (maksymalna iloœæ siarki, któr¹ mo¿na daæ/odebraæ to 32767)
//4 bajty na zwiêkszenie siê ilosci kryszta³u (zapis normalny) lub ff,ff,ff,ff - iloœæ kryszta³u do odebrania (maksymalna iloœæ kryszta³u, któr¹ mo¿na daæ/odebraæ to 32767)
//4 bajty na zwiêkszenie siê ilosci klejnotów (zapis normalny) lub ff,ff,ff,ff - iloœæ klejnotów do odebrania (maksymalna iloœæ klejnotów, któr¹ mo¿na daæ/odebraæ to 32767)
//4 bajty na zwiêkszenie siê ilosci z³ota (zapis normalny) lub ff,ff,ff,ff - iloœæ z³ota do odebrania (maksymalna iloœæ z³ota, któr¹ mo¿na daæ/odebraæ to 32767)
//1 bajt - których graczy dotyczy zdarzenie (pole bitowe, +1 - pierwszy, +2 - drugi, +4 - trzeci, +8 - czwarty, +16 - pi¹ty, +32 - szósty, +64 - siódmy, +128 - ósmy)
//1 bajt - czy zdarzenie odnosi siê do graczy - ludzi (00 - nie, 01 - tak)
//1 bajt - czy zdarzenie odnosi siê do graczy komputerowych (00 - nie, 01 - tak)
//2 bajty - opóŸnienie pierwszego wyst¹pienia (w dniach, zapis normalny, maks 671)
//1 bajt - co ile dni wystêpuje zdarzenie (maks 28, 00 oznacza zdarzenie jednorazowe)
//17 bajtów zerowych
};
struct TerrainTile
{
EterrainType tertype; // type of terrain
unsigned int terview; // look of terrain
Eriver nuine; // type of Eriver (0 if there is no Eriver)
unsigned int rivDir; // direction of Eriver
Eroad malle; // type of Eroad (0 if there is no Eriver)
unsigned int roadDir; // direction of Eroad
unsigned int siodmyTajemniczyBajt; // mysterius byte // jak bedzie waidomo co to, to sie nazwie inaczej
};
struct DefInfo //information from def declaration
{
std::string name;
int bytes [46];
};
struct SheroName //name of starting hero
{
int heroID;
std::string heroName;
};
struct PlayerInfo
{
bool canHumanPlay;
bool canComputerPlay;
unsigned int AITactic; //(00 - random, 01 - warrior, 02 - builder, 03 - explorer)
unsigned int allowedFactions; //(01 - castle; 02 - rampart; 04 - tower; 08 - inferno; 16 - necropolis; 32 - dungeon; 64 - stronghold; 128 - fortress; 256 - conflux);
bool isFactionRandom;
unsigned int mainHeroPortrait; //it's ID of hero with choosen portrait; 255 if standard
std::string mainHeroName;
std::vector<SheroName> heroesNames;
};
struct Location
{
int x, y;
bool z; // underground
};
struct LossCondition
{
ElossCon typeOfLossCon;
union
{
Location castlePos;
Location heroPos;
int timeLimit; // in days
};
};
struct CspecificVictoryConidtions
{
bool allowNormalVictory;
bool appliesToAI;
};
struct VicCon0 : public CspecificVictoryConidtions //acquire artifact
{
int ArtifactID;
};
struct VicCon1 : public CspecificVictoryConidtions //accumulate creatures
{
int monsterID;
int neededQuantity;
};
struct VicCon2 : public CspecificVictoryConidtions // accumulate resources
{
int resourceID;
int neededQuantity;
};
struct VicCon3 : public CspecificVictoryConidtions // upgrade specific town
{
Location posOfCity;
int councilNeededLevel; //0 - town; 1 - city; 2 - capitol
int fortNeededLevel;// 0 - fort; 1 - citadel; 2 - castle
};
struct VicCon4 : public CspecificVictoryConidtions // build grail structure
{
bool anyLocation;
Location whereBuildGrail;
};
struct VicCon5 : public CspecificVictoryConidtions // defeat a specific hero
{
Location locationOfHero;
};
struct VicCon6 : public CspecificVictoryConidtions // capture a specific town
{
Location locationOfTown;
};
struct VicCon7 : public CspecificVictoryConidtions // defeat a specific monster
{
Location locationOfMonster;
};
/*struct VicCon8 : public CspecificVictoryConidtions // flag all creature dwellings
{
};
struct VicCon9 : public CspecificVictoryConidtions // flag all mines
{
};*/
struct VicCona : public CspecificVictoryConidtions //transport specific artifact
{
int artifactID;
Location destinationPlace;
};
struct Rumor
{
std::string name, text;
};
struct Mapa
{
Eformat version; // version of map Eformat
bool 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<DefInfo> defy; // list of .def files
PlayerInfo players[8]; // info about players
std::vector<int> teams; // teams[i] = team of player nr i
LossCondition lossCondition;
EvictoryConditions victoryCondition; //victory conditions
CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
};
#endif //MAPD

65
mapHandler.cpp Normal file
View File

@ -0,0 +1,65 @@
#include "stdafx.h"
#include "mapHandler.h"
#include "CSemiDefHandler.h"
#include "SDL_rotozoom.h"
extern SDL_Surface * ekran;
void mapHandler::init()
{
terrainBitmap = new SDL_Surface **[reader->map.width];
for (int ii=0;ii<reader->map.width;ii++)
terrainBitmap[ii] = new SDL_Surface*[reader->map.height]; // allocate memory
for (int i=0; i<reader->map.width; i++)
{
for (int j=0; j<reader->map.height;j++)
{
TerrainTile zz = reader->map.terrain[i][j];
std::string name = CSemiDefHandler::nameFromType(reader->map.terrain[i][j].tertype);
for (int k=0; k<reader->defs.size(); k++)
{
if (reader->defs[k]->defName != name)
continue;
else
{
SDL_Surface * n;
int ktora = reader->map.terrain[i][j].terview;
terrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
//TODO: odwracanie
//SDL_BlitSurface(terrainBitmap[i][j],NULL,ekran,NULL); SDL_Flip(ekran);SDL_Delay(50);
break;
}
}
}
}
}
SDL_Surface * mapHandler::terrainRect(int x, int y, int dx, int dy)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int rmask = 0xff000000;
int gmask = 0x00ff0000;
int bmask = 0x0000ff00;
int amask = 0x000000ff;
#else
int rmask = 0x000000ff;
int gmask = 0x0000ff00;
int bmask = 0x00ff0000;
int amask = 0xff000000;
#endif
SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32,
rmask, gmask, bmask, amask);
for (int bx=0; bx<dx; bx++)
{
for (int by=0; by<dy; by++)
{
SDL_Rect * sr = new SDL_Rect;
sr->y=by*32;
sr->x=bx*32;
sr->h=sr->w=32;
SDL_BlitSurface(terrainBitmap[bx][by],NULL,su,sr);
//SDL_BlitSurface(su,NULL,ekran,NULL);SDL_Flip(ekran);
}
}
return su;
}

11
mapHandler.h Normal file
View File

@ -0,0 +1,11 @@
#include "CAmbarCendamo.h"
class mapHandler
{
public:
CAmbarCendamo * reader;
SDL_Surface *** terrainBitmap;
SDL_Surface *** undTerrainBitmap; // used only if there is underground level
SDL_Surface * terrainRect(int x, int y, int dx, int dy);
SDL_Surface mirrorImage(SDL_Surface *src);
void init();
};

8
stdafx.cpp Normal file
View File

@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// CMT.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

16
stdafx.h Normal file
View File

@ -0,0 +1,16 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <vector>
// TODO: reference additional headers your program requires here