Selaa lähdekoodia

Na początek.

Michał W. Urbańczyk 18 vuotta sitten
vanhempi
sitoutus
01e84b9e40
13 muutettua tiedostoa jossa 2187 lisäystä ja 0 poistoa
  1. 337 0
      CAmbarCendamo.cpp
  2. 29 0
      CAmbarCendamo.h
  3. 139 0
      CSemiDefHandler.cpp
  4. 28 0
      CSemiDefHandler.h
  5. 1231 0
      SDL_rotozoom.cpp
  6. 117 0
      SDL_rotozoom.h
  7. 12 0
      global.h
  8. 47 0
      inde.cpp
  9. 147 0
      map.h
  10. 65 0
      mapHandler.cpp
  11. 11 0
      mapHandler.h
  12. 8 0
      stdafx.cpp
  13. 16 0
      stdafx.h

+ 337 - 0
CAmbarCendamo.cpp

@@ -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 - 0
CAmbarCendamo.h

@@ -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 - 0
CSemiDefHandler.cpp

@@ -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 - 0
CSemiDefHandler.h

@@ -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 - 0
SDL_rotozoom.cpp

@@ -0,0 +1,1231 @@
+/*  
+
+  SDL_rotozoom.c - rotozoomer for 32bit or 8bit surfaces
+
+  LGPL (c) A. Schiffler
+
+*/
+#include "stdafx.h"
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "SDL_rotozoom.h"
+
+#define MAX(a,b)    (((a) > (b)) ? (a) : (b))
+
+
+/* 
+ 
+ 32bit integer-factor averaging Shrinker
+
+ Shrinks 32bit RGBA/ABGR 'src' surface to 'dst' surface.
+ 
+*/
+
+int shrinkSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int factorx, int factory)
+{
+    int x, y, dx, dy, sgap, dgap, ra, ga, ba, aa;
+    int n_average;
+    tColorRGBA *sp, *osp, *oosp;
+    tColorRGBA *dp;
+
+    /*
+     * Averaging integer shrink
+     */
+
+    /* Precalculate division factor */
+    n_average = factorx*factory;
+   
+    /*
+     * Scan destination
+     */
+    sp = (tColorRGBA *) src->pixels;
+    sgap = src->pitch - src->w * 4;
+
+    dp = (tColorRGBA *) dst->pixels;
+    dgap = dst->pitch - dst->w * 4;
+
+    for (y = 0; y < dst->h; y++) {
+
+      osp=sp;
+      for (x = 0; x < dst->w; x++) {
+
+        /* Trace out source box and accumulate */
+        oosp=sp;
+        ra=ga=ba=aa=0;
+        for (dy=0; dy < factory; dy++) {
+         for (dx=0; dx < factorx; dx++) {
+          ra += sp->r;
+          ga += sp->g;
+          ba += sp->b;
+          aa += sp->a;
+          
+          sp++;
+         } // src dx loop
+         sp = (tColorRGBA *)((Uint8*)sp + (src->pitch - 4*factorx)); // next y
+        } // src dy loop
+
+        // next box-x
+        sp = (tColorRGBA *)((Uint8*)oosp + 4*factorx);
+                
+        /* Store result in destination */
+        dp->r = ra/n_average;
+        dp->g = ga/n_average;
+        dp->b = ba/n_average;
+        dp->a = aa/n_average;
+                 
+        /*
+         * Advance destination pointer 
+         */
+         dp++;
+        } // dst x loop
+
+        // next box-y
+        sp = (tColorRGBA *)((Uint8*)osp + src->pitch*factory);
+
+        /*
+         * Advance destination pointers 
+         */
+        dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
+      } // dst y loop
+
+    return (0);
+}
+
+/* 
+ 
+ 8bit integer-factor averaging Shrinker
+
+ Shrinks 8bit Y 'src' surface to 'dst' surface.
+ 
+*/
+
+int shrinkSurfaceY(SDL_Surface * src, SDL_Surface * dst, int factorx, int factory)
+{
+    int x, y, dx, dy, sgap, dgap, a;
+    int n_average;
+    Uint8 *sp, *osp, *oosp;
+    Uint8 *dp;
+
+    /*
+     * Averaging integer shrink
+     */
+
+    /* Precalculate division factor */
+    n_average = factorx*factory;
+   
+    /*
+     * Scan destination
+     */
+    sp = (Uint8 *) src->pixels;
+    sgap = src->pitch - src->w;
+
+    dp = (Uint8 *) dst->pixels;
+    dgap = dst->pitch - dst->w;
+    
+    for (y = 0; y < dst->h; y++) {    
+
+      osp=sp;
+      for (x = 0; x < dst->w; x++) {
+
+        /* Trace out source box and accumulate */
+        oosp=sp;
+        a=0;
+        for (dy=0; dy < factory; dy++) {
+         for (dx=0; dx < factorx; dx++) {
+          a += (*sp);           
+          sp++; // next x
+         } // src dx loop         
+         sp = (Uint8 *)((Uint8*)sp + (src->pitch - factorx)); // next y
+        } // src dy loop
+        
+        // next box-x
+        sp = (Uint8 *)((Uint8*)oosp + factorx);
+                
+        /* Store result in destination */
+        *dp = a/n_average;
+
+        /*
+         * Advance destination pointer 
+         */
+         dp++;
+        } // dst x loop
+
+        // next box-y
+        sp = (Uint8 *)((Uint8*)osp + src->pitch*factory);
+
+        /*
+         * Advance destination pointers 
+         */
+        dp = (Uint8 *)((Uint8 *)dp + dgap);
+      } // dst y loop
+
+    return (0);
+}
+
+/* 
+ 
+ 32bit Zoomer with optional anti-aliasing by bilinear interpolation.
+
+ Zoomes 32bit RGBA/ABGR 'src' surface to 'dst' surface.
+ 
+*/
+
+int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy, int smooth)
+{
+    int x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy, ex, ey, t1, t2, sstep;
+    tColorRGBA *c00, *c01, *c10, *c11;
+    tColorRGBA *sp, *csp, *dp;
+    int dgap;
+
+    /*
+     * Variable setup 
+     */
+    if (smooth) {
+	/*
+	 * For interpolation: assume source dimension is one pixel 
+	 */
+	/*
+	 * smaller to avoid overflow on right and bottom edge.     
+	 */
+	sx = (int) (65536.0 * (float) (src->w - 1) / (float) dst->w);
+	sy = (int) (65536.0 * (float) (src->h - 1) / (float) dst->h);
+    } else {
+	sx = (int) (65536.0 * (float) src->w / (float) dst->w);
+	sy = (int) (65536.0 * (float) src->h / (float) dst->h);
+    }
+
+    /*
+     * Allocate memory for row increments 
+     */
+    if ((sax = (int *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL) {
+	return (-1);
+    }
+    if ((say = (int *) malloc((dst->h + 1) * sizeof(Uint32))) == NULL) {
+	free(sax);
+	return (-1);
+    }
+
+    /*
+     * Precalculate row increments 
+     */
+    sp = csp = (tColorRGBA *) src->pixels;
+    dp = (tColorRGBA *) dst->pixels;
+
+    if (flipx) csp += (src->w-1);
+    if (flipy) csp  = (tColorRGBA*)( (Uint8*)csp + src->pitch*(src->h-1) );
+
+    csx = 0;
+    csax = sax;
+    for (x = 0; x <= dst->w; x++) {
+	*csax = csx;
+	csax++;
+	csx &= 0xffff;
+	csx += sx;
+    }
+    csy = 0;
+    csay = say;
+    for (y = 0; y <= dst->h; y++) {
+	*csay = csy;
+	csay++;
+	csy &= 0xffff;
+	csy += sy;
+    }
+
+    dgap = dst->pitch - dst->w * 4;
+
+    /*
+     * Switch between interpolating and non-interpolating code 
+     */
+    if (smooth) {
+
+	/*
+	 * Interpolating Zoom 
+	 */
+
+	/*
+	 * Scan destination 
+	 */
+	csay = say;
+	for (y = 0; y < dst->h; y++) {
+	    /*
+	     * Setup color source pointers 
+	     */
+	    c00 = csp;
+	    c01 = csp;
+	    c01++;
+	    c10 = (tColorRGBA *) ((Uint8 *) csp + src->pitch);
+	    c11 = c10;
+	    c11++;
+	    csax = sax;
+	    for (x = 0; x < dst->w; x++) {
+
+		/*
+		 * Interpolate colors 
+		 */
+		ex = (*csax & 0xffff);
+		ey = (*csay & 0xffff);
+		t1 = ((((c01->r - c00->r) * ex) >> 16) + c00->r) & 0xff;
+		t2 = ((((c11->r - c10->r) * ex) >> 16) + c10->r) & 0xff;
+		dp->r = (((t2 - t1) * ey) >> 16) + t1;
+		t1 = ((((c01->g - c00->g) * ex) >> 16) + c00->g) & 0xff;
+		t2 = ((((c11->g - c10->g) * ex) >> 16) + c10->g) & 0xff;
+		dp->g = (((t2 - t1) * ey) >> 16) + t1;
+		t1 = ((((c01->b - c00->b) * ex) >> 16) + c00->b) & 0xff;
+		t2 = ((((c11->b - c10->b) * ex) >> 16) + c10->b) & 0xff;
+		dp->b = (((t2 - t1) * ey) >> 16) + t1;
+		t1 = ((((c01->a - c00->a) * ex) >> 16) + c00->a) & 0xff;
+		t2 = ((((c11->a - c10->a) * ex) >> 16) + c10->a) & 0xff;
+		dp->a = (((t2 - t1) * ey) >> 16) + t1;
+
+		/*
+		 * Advance source pointers 
+		 */
+		csax++;
+		sstep = (*csax >> 16);
+		c00 += sstep;
+		c01 += sstep;
+		c10 += sstep;
+		c11 += sstep;
+		/*
+		 * Advance destination pointer 
+		 */
+		dp++;
+	    }
+	    /*
+	     * Advance source pointer 
+	     */
+	    csay++;
+	    csp = (tColorRGBA *) ((Uint8 *) csp + (*csay >> 16) * src->pitch);
+	    /*
+	     * Advance destination pointers 
+	     */
+	    dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
+	}
+
+    } else {
+
+	/*
+	 * Non-Interpolating Zoom 
+	 */
+
+	csay = say;
+	for (y = 0; y < dst->h; y++) {
+	    sp = csp;
+	    csax = sax;
+	    for (x = 0; x < dst->w; x++) {
+		/*
+		 * Draw 
+		 */
+		*dp = *sp;
+		/*
+		 * Advance source pointers 
+		 */
+		csax++;
+		sstep = (*csax >> 16);
+		if (flipx) sstep = -sstep;
+		sp += sstep;
+		/*
+		 * Advance destination pointer 
+		 */
+		dp++;
+	    }
+	    /*
+	     * Advance source pointer 
+	     */
+	    csay++;
+	    sstep = (*csay >> 16) * src->pitch;
+	    if (flipy) sstep = -sstep;
+	    csp = (tColorRGBA *) ((Uint8 *) csp + sstep);
+
+	    /*
+	     * Advance destination pointers 
+	     */
+	    dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
+	}
+
+    }
+
+    /*
+     * Remove temp arrays 
+     */
+    free(sax);
+    free(say);
+
+    return (0);
+}
+
+/* 
+ 
+ 8bit Zoomer without smoothing.
+
+ Zoomes 8bit palette/Y 'src' surface to 'dst' surface.
+ 
+*/
+
+int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy)
+{
+    Uint32 x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy;
+    Uint8 *sp, *dp, *csp;
+    int dgap;
+
+    /*
+     * Variable setup 
+     */
+    sx = (Uint32) (65536.0 * (float) src->w / (float) dst->w);
+    sy = (Uint32) (65536.0 * (float) src->h / (float) dst->h);
+
+    /*
+     * Allocate memory for row increments 
+     */
+    if ((sax = (Uint32 *) malloc(dst->w * sizeof(Uint32))) == NULL) {
+	return (-1);
+    }
+    if ((say = (Uint32 *) malloc(dst->h * sizeof(Uint32))) == NULL) {
+	if (sax != NULL) {
+	    free(sax);
+	}
+	return (-1);
+    }
+
+    /*
+     * Precalculate row increments 
+     */
+    csx = 0;
+    csax = sax;
+    for (x = 0; x < dst->w; x++) {
+	csx += sx;
+	*csax = (csx >> 16);
+	csx &= 0xffff;
+	csax++;
+    }
+    csy = 0;
+    csay = say;
+    for (y = 0; y < dst->h; y++) {
+	csy += sy;
+	*csay = (csy >> 16);
+	csy &= 0xffff;
+	csay++;
+    }
+
+    csx = 0;
+    csax = sax;
+    for (x = 0; x < dst->w; x++) {
+	csx += (*csax);
+	csax++;
+    }
+    csy = 0;
+    csay = say;
+    for (y = 0; y < dst->h; y++) {
+	csy += (*csay);
+	csay++;
+    }
+
+    /*
+     * Pointer setup 
+     */
+    sp = csp = (Uint8 *) src->pixels;
+    dp = (Uint8 *) dst->pixels;
+    dgap = dst->pitch - dst->w;
+
+    /*
+     * Draw 
+     */
+    csay = say;
+    for (y = 0; y < dst->h; y++) {
+	csax = sax;
+	sp = csp;
+	for (x = 0; x < dst->w; x++) {
+	    /*
+	     * Draw 
+	     */
+	    *dp = *sp;
+	    /*
+	     * Advance source pointers 
+	     */
+	    sp += (*csax);
+	    csax++;
+	    /*
+	     * Advance destination pointer 
+	     */
+	    dp++;
+	}
+	/*
+	 * Advance source pointer (for row) 
+	 */
+	csp += ((*csay) * src->pitch);
+	csay++;
+	/*
+	 * Advance destination pointers 
+	 */
+	dp += dgap;
+    }
+
+    /*
+     * Remove temp arrays 
+     */
+    free(sax);
+    free(say);
+
+    return (0);
+}
+
+/* 
+ 
+ 32bit Rotozoomer with optional anti-aliasing by bilinear interpolation.
+
+ Rotates and zoomes 32bit RGBA/ABGR 'src' surface to 'dst' surface.
+ 
+*/
+
+void transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth)
+{
+    int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh;
+    tColorRGBA c00, c01, c10, c11;
+    tColorRGBA *pc, *sp;
+    int gap;
+
+    /*
+     * Variable setup 
+     */
+    xd = ((src->w - dst->w) << 15);
+    yd = ((src->h - dst->h) << 15);
+    ax = (cx << 16) - (icos * cx);
+    ay = (cy << 16) - (isin * cx);
+    sw = src->w - 1;
+    sh = src->h - 1;
+    pc = (tColorRGBA*)dst->pixels;
+    gap = dst->pitch - dst->w * 4;
+
+    /*
+     * Switch between interpolating and non-interpolating code 
+     */
+    if (smooth) {
+	for (y = 0; y < dst->h; y++) {
+	    dy = cy - y;
+	    sdx = (ax + (isin * dy)) + xd;
+	    sdy = (ay - (icos * dy)) + yd;
+	    for (x = 0; x < dst->w; x++) {
+		dx = (sdx >> 16);
+		dy = (sdy >> 16);
+		if ((dx >= -1) && (dy >= -1) && (dx < src->w) && (dy < src->h)) {
+		    if ((dx >= 0) && (dy >= 0) && (dx < sw) && (dy < sh)) {
+			sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
+			sp += dx;
+			c00 = *sp;
+			sp += 1;
+			c01 = *sp;
+			sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch);
+			sp -= 1;
+			c10 = *sp;
+			sp += 1;
+			c11 = *sp;
+		    } else if ((dx == sw) && (dy == sh)) {
+			sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
+			sp += dx;
+			c00 = *sp;
+			c01 = *sp;
+			c10 = *sp;
+			c11 = *sp;
+		    } else if ((dx == -1) && (dy == -1)) {
+			sp = (tColorRGBA *) (src->pixels);
+			c00 = *sp;
+			c01 = *sp;
+			c10 = *sp;
+			c11 = *sp;
+		    } else if ((dx == -1) && (dy == sh)) {
+			sp = (tColorRGBA *) (src->pixels);
+			sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
+			c00 = *sp;
+			c01 = *sp;
+			c10 = *sp;
+			c11 = *sp;
+		    } else if ((dx == sw) && (dy == -1)) {
+			sp = (tColorRGBA *) (src->pixels);
+			sp += dx;
+			c00 = *sp;
+			c01 = *sp;
+			c10 = *sp;
+			c11 = *sp;
+		    } else if (dx == -1) {
+			sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
+			c00 = *sp;
+			c01 = *sp;
+			c10 = *sp;
+			sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch);
+			c11 = *sp;
+		    } else if (dy == -1) {
+			sp = (tColorRGBA *) (src->pixels);
+			sp += dx;
+			c00 = *sp;
+			c01 = *sp;
+			c10 = *sp;
+			sp += 1;
+			c11 = *sp;
+		    } else if (dx == sw) {
+			sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
+			sp += dx;
+			c00 = *sp;
+			c01 = *sp;
+			sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch);
+			c10 = *sp;
+			c11 = *sp;
+		    } else if (dy == sh) {
+			sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
+			sp += dx;
+			c00 = *sp;
+			sp += 1;
+			c01 = *sp;
+			c10 = *sp;
+			c11 = *sp;
+		    }
+		    /*
+		     * Interpolate colors 
+		     */
+		    ex = (sdx & 0xffff);
+		    ey = (sdy & 0xffff);
+		    t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff;
+		    t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff;
+		    pc->r = (((t2 - t1) * ey) >> 16) + t1;
+		    t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff;
+		    t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff;
+		    pc->g = (((t2 - t1) * ey) >> 16) + t1;
+		    t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff;
+		    t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff;
+		    pc->b = (((t2 - t1) * ey) >> 16) + t1;
+		    t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff;
+		    t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff;
+		    pc->a = (((t2 - t1) * ey) >> 16) + t1;
+		}
+		sdx += icos;
+		sdy += isin;
+		pc++;
+	    }
+	    pc = (tColorRGBA *) ((Uint8 *) pc + gap);
+	}
+    } else {
+	for (y = 0; y < dst->h; y++) {
+	    dy = cy - y;
+	    sdx = (ax + (isin * dy)) + xd;
+	    sdy = (ay - (icos * dy)) + yd;
+	    for (x = 0; x < dst->w; x++) {
+		dx = (short) (sdx >> 16);
+		dy = (short) (sdy >> 16);
+		if (flipx) dx = (src->w-1)-dx;
+		if (flipy) dy = (src->h-1)-dy;
+		if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) {
+		    sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy);
+		    sp += dx;
+		    *pc = *sp;
+		}
+		sdx += icos;
+		sdy += isin;
+		pc++;
+	    }
+	    pc = (tColorRGBA *) ((Uint8 *) pc + gap);
+	}
+    }
+}
+
+/* 
+ 
+ 8bit Rotozoomer without smoothing
+
+ Rotates and zoomes 8bit palette/Y 'src' surface to 'dst' surface.
+ 
+*/
+
+void transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos)
+{
+    int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay, sw, sh;
+    tColorY *pc, *sp;
+    int gap;
+
+    /*
+     * Variable setup 
+     */
+    xd = ((src->w - dst->w) << 15);
+    yd = ((src->h - dst->h) << 15);
+    ax = (cx << 16) - (icos * cx);
+    ay = (cy << 16) - (isin * cx);
+    sw = src->w - 1;
+    sh = src->h - 1;
+    pc = (tColorY*)dst->pixels;
+    gap = dst->pitch - dst->w;
+    /*
+     * Clear surface to colorkey 
+     */
+    memset(pc, (unsigned char) (src->format->colorkey & 0xff), dst->pitch * dst->h);
+    /*
+     * Iterate through destination surface 
+     */
+    for (y = 0; y < dst->h; y++) {
+	dy = cy - y;
+	sdx = (ax + (isin * dy)) + xd;
+	sdy = (ay - (icos * dy)) + yd;
+	for (x = 0; x < dst->w; x++) {
+	    dx = (short) (sdx >> 16);
+	    dy = (short) (sdy >> 16);
+	    if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) {
+		sp = (tColorY *) (src->pixels);
+		sp += (src->pitch * dy + dx);
+		*pc = *sp;
+	    }
+	    sdx += icos;
+	    sdy += isin;
+	    pc++;
+	}
+	pc += gap;
+    }
+}
+
+/* 
+ 
+ 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.
+
+*/
+
+#define VALUE_LIMIT	0.001
+
+
+/* Local rotozoom-size function with trig result return */
+
+void rotozoomSurfaceSizeTrig(int width, int height, double angle, double zoomx, double zoomy, int *dstwidth, int *dstheight, 
+			     double *canglezoom, double *sanglezoom)
+{
+    double x, y, cx, cy, sx, sy;
+    double radangle;
+    int dstwidthhalf, dstheighthalf;
+
+    /*
+     * Determine destination width and height by rotating a centered source box 
+     */
+    radangle = angle * (M_PI / 180.0);
+    *sanglezoom = sin(radangle);
+    *canglezoom = cos(radangle);
+    *sanglezoom *= zoomx;
+    *canglezoom *= zoomx;
+    x = width / 2;
+    y = height / 2;
+    cx = *canglezoom * x;
+    cy = *canglezoom * y;
+    sx = *sanglezoom * x;
+    sy = *sanglezoom * y;
+    
+    dstwidthhalf = MAX((int)
+		       ceil(MAX(MAX(MAX(fabs(cx + sy), fabs(cx - sy)), fabs(-cx + sy)), fabs(-cx - sy))), 1);
+    dstheighthalf = MAX((int)
+			ceil(MAX(MAX(MAX(fabs(sx + cy), fabs(sx - cy)), fabs(-sx + cy)), fabs(-sx - cy))), 1);
+    *dstwidth = 2 * dstwidthhalf;
+    *dstheight = 2 * dstheighthalf;
+}
+
+
+/* Publically available rotozoom-size function */
+
+void rotozoomSurfaceSizeXY(int width, int height, double angle, double zoomx, double zoomy, int *dstwidth, int *dstheight)
+{
+    double dummy_sanglezoom, dummy_canglezoom;
+
+    rotozoomSurfaceSizeTrig(width, height, angle, zoomx, zoomy, dstwidth, dstheight, &dummy_sanglezoom, &dummy_canglezoom);
+}
+
+/* Publically available rotozoom-size function */
+
+void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth, int *dstheight)
+{
+    double dummy_sanglezoom, dummy_canglezoom;
+
+    rotozoomSurfaceSizeTrig(width, height, angle, zoom, zoom, dstwidth, dstheight, &dummy_sanglezoom, &dummy_canglezoom);
+}
+
+/* Publically available rotozoom function */
+
+SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth)
+{
+  return rotozoomSurfaceXY(src, angle, zoom, zoom, smooth);
+}
+
+/* Publically available rotozoom function */
+
+SDL_Surface *rotozoomSurfaceXY(SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth)
+{
+    SDL_Surface *rz_src;
+    SDL_Surface *rz_dst;
+    double zoominv;
+    double sanglezoom, canglezoom, sanglezoominv, canglezoominv;
+    int dstwidthhalf, dstwidth, dstheighthalf, dstheight;
+    int is32bit;
+    int i, src_converted;
+    int flipx,flipy;
+
+    /*
+     * Sanity check 
+     */
+    if (src == NULL)
+	return (NULL);
+
+    /*
+     * Determine if source surface is 32bit or 8bit 
+     */
+    is32bit = (src->format->BitsPerPixel == 32);
+    if ((is32bit) || (src->format->BitsPerPixel == 8)) {
+	/*
+	 * Use source surface 'as is' 
+	 */
+	rz_src = src;
+	src_converted = 0;
+    } else {
+	/*
+	 * New source surface is 32bit with a defined RGBA ordering 
+	 */
+	rz_src =
+	    SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+	SDL_BlitSurface(src, NULL, rz_src, NULL);
+	src_converted = 1;
+	is32bit = 1;
+    }
+
+    /*
+     * Sanity check zoom factor 
+     */
+    flipx = (zoomx<0);
+    if (flipx) zoomx=-zoomx;
+    flipy = (zoomy<0);
+    if (flipy) zoomy=-zoomy;
+    if (zoomx < VALUE_LIMIT) zoomx = VALUE_LIMIT;
+    if (zoomy < VALUE_LIMIT) zoomy = VALUE_LIMIT;
+    zoominv = 65536.0 / (zoomx * zoomx);
+
+    /*
+     * Check if we have a rotozoom or just a zoom 
+     */
+    if (fabs(angle) > VALUE_LIMIT) {
+
+	/*
+	 * Angle!=0: full rotozoom 
+	 */
+	/*
+	 * ----------------------- 
+	 */
+
+	/* Determine target size */
+	rotozoomSurfaceSizeTrig(rz_src->w, rz_src->h, angle, zoomx, zoomy, &dstwidth, &dstheight, &canglezoom, &sanglezoom);
+
+	/*
+	 * Calculate target factors from sin/cos and zoom 
+	 */
+	sanglezoominv = sanglezoom;
+	canglezoominv = canglezoom;
+	sanglezoominv *= zoominv;
+	canglezoominv *= zoominv;
+
+	/* Calculate half size */
+	dstwidthhalf = dstwidth / 2;
+	dstheighthalf = dstheight / 2;
+
+	/*
+	 * Alloc space to completely contain the rotated surface 
+	 */
+	rz_dst = NULL;
+	if (is32bit) {
+	    /*
+	     * Target surface is 32bit with source RGBA/ABGR ordering 
+	     */
+	    rz_dst =
+		SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32,
+				     rz_src->format->Rmask, rz_src->format->Gmask,
+				     rz_src->format->Bmask, rz_src->format->Amask);
+	} else {
+	    /*
+	     * Target surface is 8bit 
+	     */
+	    rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0);
+	}
+
+	/*
+	 * Lock source surface 
+	 */
+	SDL_LockSurface(rz_src);
+	/*
+	 * Check which kind of surface we have 
+	 */
+	if (is32bit) {
+	    /*
+	     * Call the 32bit transformation routine to do the rotation (using alpha) 
+	     */
+	    transformSurfaceRGBA(rz_src, rz_dst, dstwidthhalf, dstheighthalf,
+				 (int) (sanglezoominv), (int) (canglezoominv), 
+				 flipx, flipy,
+				 smooth);
+	    /*
+	     * Turn on source-alpha support 
+	     */
+	    SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
+	} else {
+	    /*
+	     * Copy palette and colorkey info 
+	     */
+	    for (i = 0; i < rz_src->format->palette->ncolors; i++) {
+		rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
+	    }
+	    rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
+	    /*
+	     * Call the 8bit transformation routine to do the rotation 
+	     */
+	    transformSurfaceY(rz_src, rz_dst, dstwidthhalf, dstheighthalf,
+			      (int) (sanglezoominv), (int) (canglezoominv));
+	    SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey);
+	}
+	/*
+	 * Unlock source surface 
+	 */
+	SDL_UnlockSurface(rz_src);
+
+    } else {
+
+	/*
+	 * Angle=0: Just a zoom 
+	 */
+	/*
+	 * -------------------- 
+	 */
+
+	/*
+	 * Calculate target size
+	 */
+	zoomSurfaceSize(rz_src->w, rz_src->h, zoomx, zoomy, &dstwidth, &dstheight);
+
+	/*
+	 * Alloc space to completely contain the zoomed surface 
+	 */
+	rz_dst = NULL;
+	if (is32bit) {
+	    /*
+	     * Target surface is 32bit with source RGBA/ABGR ordering 
+	     */
+	    rz_dst =
+		SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32,
+				     rz_src->format->Rmask, rz_src->format->Gmask,
+				     rz_src->format->Bmask, rz_src->format->Amask);
+	} else {
+	    /*
+	     * Target surface is 8bit 
+	     */
+	    rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0);
+	}
+
+	/*
+	 * Lock source surface 
+	 */
+	SDL_LockSurface(rz_src);
+	/*
+	 * Check which kind of surface we have 
+	 */
+	if (is32bit) {
+	    /*
+	     * Call the 32bit transformation routine to do the zooming (using alpha) 
+	     */
+	    zoomSurfaceRGBA(rz_src, rz_dst, flipx, flipy, smooth);
+	    /*
+	     * Turn on source-alpha support 
+	     */
+	    SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
+	} else {
+	    /*
+	     * Copy palette and colorkey info 
+	     */
+	    for (i = 0; i < rz_src->format->palette->ncolors; i++) {
+		rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
+	    }
+	    rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
+	    /*
+	     * Call the 8bit transformation routine to do the zooming 
+	     */
+	    zoomSurfaceY(rz_src, rz_dst, flipx, flipy);
+	    SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey);
+	}
+	/*
+	 * Unlock source surface 
+	 */
+	SDL_UnlockSurface(rz_src);
+    }
+
+    /*
+     * Cleanup temp surface 
+     */
+    if (src_converted) {
+	SDL_FreeSurface(rz_src);
+    }
+
+    /*
+     * Return destination surface 
+     */
+    return (rz_dst);
+}
+
+/* 
+ 
+ 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.
+
+*/
+
+#define VALUE_LIMIT	0.001
+
+void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight)
+{
+    /*
+     * Sanity check zoom factors 
+     */
+    if (zoomx < VALUE_LIMIT) {
+	zoomx = VALUE_LIMIT;
+    }
+    if (zoomy < VALUE_LIMIT) {
+	zoomy = VALUE_LIMIT;
+    }
+
+    /*
+     * Calculate target size 
+     */
+    *dstwidth = (int) ((double) width * zoomx);
+    *dstheight = (int) ((double) height * zoomy);
+    if (*dstwidth < 1) {
+	*dstwidth = 1;
+    }
+    if (*dstheight < 1) {
+	*dstheight = 1;
+    }
+}
+
+SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth)
+{
+    SDL_Surface *rz_src;
+    SDL_Surface *rz_dst;
+    int dstwidth, dstheight;
+    int is32bit;
+    int i, src_converted;
+    int flipx, flipy;
+
+    /*
+     * Sanity check 
+     */
+    if (src == NULL)
+	return (NULL);
+
+    /*
+     * Determine if source surface is 32bit or 8bit 
+     */
+    is32bit = (src->format->BitsPerPixel == 32);
+    if ((is32bit) || (src->format->BitsPerPixel == 8)) {
+	/*
+	 * Use source surface 'as is' 
+	 */
+	rz_src = src;
+	src_converted = 0;
+    } else {
+	/*
+	 * New source surface is 32bit with a defined RGBA ordering 
+	 */
+	rz_src =
+	    SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+	SDL_BlitSurface(src, NULL, rz_src, NULL);
+	src_converted = 1;
+	is32bit = 1;
+    }
+
+    flipx = (zoomx<0);
+    if (flipx) zoomx = -zoomx;
+    flipy = (zoomy<0);
+    if (flipy) zoomy = -zoomy;
+
+    /* Get size if target */
+    zoomSurfaceSize(rz_src->w, rz_src->h, zoomx, zoomy, &dstwidth, &dstheight);
+
+    /*
+     * Alloc space to completely contain the zoomed surface 
+     */
+    rz_dst = NULL;
+    if (is32bit) {
+	/*
+	 * Target surface is 32bit with source RGBA/ABGR ordering 
+	 */
+	rz_dst =
+	    SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32,
+				 rz_src->format->Rmask, rz_src->format->Gmask,
+				 rz_src->format->Bmask, rz_src->format->Amask);
+    } else {
+	/*
+	 * Target surface is 8bit 
+	 */
+	rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0);
+    }
+
+    /*
+     * Lock source surface 
+     */
+    SDL_LockSurface(rz_src);
+    /*
+     * Check which kind of surface we have 
+     */
+    if (is32bit) {
+	/*
+	 * Call the 32bit transformation routine to do the zooming (using alpha) 
+	 */
+	zoomSurfaceRGBA(rz_src, rz_dst, flipx, flipy, smooth);
+	/*
+	 * Turn on source-alpha support 
+	 */
+	SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
+    } else {
+	/*
+	 * Copy palette and colorkey info 
+	 */
+	for (i = 0; i < rz_src->format->palette->ncolors; i++) {
+	    rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
+	}
+	rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
+	/*
+	 * Call the 8bit transformation routine to do the zooming 
+	 */
+	zoomSurfaceY(rz_src, rz_dst, flipx, flipy);
+	SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey);
+    }
+    /*
+     * Unlock source surface 
+     */
+    SDL_UnlockSurface(rz_src);
+
+    /*
+     * Cleanup temp surface 
+     */
+    if (src_converted) {
+	SDL_FreeSurface(rz_src);
+    }
+
+    /*
+     * Return destination surface 
+     */
+    return (rz_dst);
+}
+
+SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory)
+{
+    SDL_Surface *rz_src;
+    SDL_Surface *rz_dst;
+    int dstwidth, dstheight;
+    int is32bit;
+    int i, src_converted;
+
+    /*
+     * Sanity check 
+     */
+    if (src == NULL)
+	return (NULL);
+
+    /*
+     * Determine if source surface is 32bit or 8bit 
+     */
+    is32bit = (src->format->BitsPerPixel == 32);
+    if ((is32bit) || (src->format->BitsPerPixel == 8)) {
+	/*
+	 * Use source surface 'as is' 
+	 */
+	rz_src = src;
+	src_converted = 0;
+    } else {
+	/*
+	 * New source surface is 32bit with a defined RGBA ordering 
+	 */
+	rz_src =
+	    SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+	SDL_BlitSurface(src, NULL, rz_src, NULL);
+	src_converted = 1;
+	is32bit = 1;
+    }
+
+    /* Get size for target */
+    dstwidth=rz_src->w/factorx;
+    while (dstwidth*factorx>rz_src->w) { dstwidth--; }
+    dstheight=rz_src->h/factory;
+    while (dstheight*factory>rz_src->h) { dstheight--; }
+
+    /*
+     * Alloc space to completely contain the shrunken surface 
+     */
+    rz_dst = NULL;
+    if (is32bit) {
+	/*
+	 * Target surface is 32bit with source RGBA/ABGR ordering 
+	 */
+	rz_dst =
+	    SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32,
+				 rz_src->format->Rmask, rz_src->format->Gmask,
+				 rz_src->format->Bmask, rz_src->format->Amask);
+    } else {
+	/*
+	 * Target surface is 8bit 
+	 */
+	rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0);
+    }
+
+    /*
+     * Lock source surface 
+     */
+    SDL_LockSurface(rz_src);
+    /*
+     * Check which kind of surface we have 
+     */
+    if (is32bit) {
+	/*
+	 * Call the 32bit transformation routine to do the shrinking (using alpha) 
+	 */
+	shrinkSurfaceRGBA(rz_src, rz_dst, factorx, factory);
+	/*
+	 * Turn on source-alpha support 
+	 */
+	SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);
+    } else {
+	/*
+	 * Copy palette and colorkey info 
+	 */
+	for (i = 0; i < rz_src->format->palette->ncolors; i++) {
+	    rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
+	}
+	rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
+	/*
+	 * Call the 8bit transformation routine to do the shrinking 
+	 */
+	shrinkSurfaceY(rz_src, rz_dst, factorx, factory);
+	SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey);
+    }
+    /*
+     * Unlock source surface 
+     */
+    SDL_UnlockSurface(rz_src);
+
+    /*
+     * Cleanup temp surface 
+     */
+    if (src_converted) {
+	SDL_FreeSurface(rz_src);
+    }
+
+    /*
+     * Return destination surface 
+     */
+    return (rz_dst);
+}

+ 117 - 0
SDL_rotozoom.h

@@ -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 - 0
global.h

@@ -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 - 0
inde.cpp

@@ -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 - 0
map.h

@@ -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 - 0
mapHandler.cpp

@@ -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 - 0
mapHandler.h

@@ -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 - 0
stdafx.cpp

@@ -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 - 0
stdafx.h

@@ -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