CMT.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. // CMT.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include "SDL.h"
  5. #include "SDL_TTF.h"
  6. #include "hch\CVideoHandler.h"
  7. #include "SDL_mixer.h"
  8. #include "hch\CBuildingHandler.h"
  9. #include "SDL_Extensions.h"
  10. #include "SDL_framerate.h"
  11. #include <cmath>
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <string>
  15. #include <assert.h>
  16. #include <vector>
  17. #include "zlib.h"
  18. #include <cmath>
  19. #include <ctime>
  20. #include "hch\CArtHandler.h"
  21. #include "hch\CHeroHandler.h"
  22. #include "hch\CCreatureHandler.h"
  23. #include "hch\CAbilityHandler.h"
  24. #include "hch\CSpellHandler.h"
  25. #include "hch\CBuildingHandler.h"
  26. #include "hch\CObjectHandler.h"
  27. #include "CGameInfo.h"
  28. #include "hch\CMusicHandler.h"
  29. #include "hch\CSemiLodHandler.h"
  30. #include "hch\CLodHandler.h"
  31. #include "hch\CDefHandler.h"
  32. #include "hch\CSndHandler.h"
  33. #include "hch\CTownHandler.h"
  34. #include "hch\CDefObjInfoHandler.h"
  35. #include "hch\CAmbarCendamo.h"
  36. #include "mapHandler.h"
  37. #include "global.h"
  38. #include "CPreGame.h"
  39. #include "hch\CGeneralTextHandler.h"
  40. #include "CConsoleHandler.h"
  41. #include "CCursorHandler.h"
  42. #include "CScreenHandler.h"
  43. #include "CPathfinder.h"
  44. #include "CGameState.h"
  45. #include "CCallback.h"
  46. #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
  47. # include <fcntl.h>
  48. # include <io.h>
  49. # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
  50. #else
  51. # define SET_BINARY_MODE(file)
  52. #endif
  53. #define CHUNK 16384
  54. const char * NAME = "VCMI 0.3 \"Tol Galen\"";
  55. SDL_Surface * ekran, * screen, * screen2;
  56. TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
  57. #include "lua.h"
  58. #include "lualib.h"
  59. #include "lauxlib.h"
  60. #include <luabind/luabind.hpp>
  61. #include <luabind/function.hpp>
  62. #include <luabind/class.hpp>
  63. #if (LUA_VERSION_NUM < 500)
  64. # define LUA_OPEN_LIB(L, lib) lib(L)
  65. #else
  66. # define LUA_OPEN_LIB(L, lib) \
  67. lua_pushcfunction((L), lib); \
  68. lua_pcall((L), 0, 0, 0);
  69. #endif
  70. void piszpowitanie2(std::string i)
  71. {
  72. std::cout<<"powitanie2zc++. Liczba dnia to " << i;
  73. }
  74. void initGameState(CGameInfo * cgi)
  75. {
  76. cgi->state->day=1;
  77. /*********creating players entries in gs****************************************/
  78. for (int i=0; i<cgi->scenarioOps.playerInfos.size();i++)
  79. {
  80. std::pair<int,PlayerState> ins(cgi->scenarioOps.playerInfos[i].color,PlayerState());
  81. cgi->state->players.insert(ins);
  82. }
  83. /******************RESOURCES****************************************************/
  84. //TODO: zeby komputer dostawal inaczej niz gracz
  85. std::vector<int> startres;
  86. std::ifstream tis("config/startres.txt");
  87. int k;
  88. for (int j=0;j<cgi->scenarioOps.difficulty;j++)
  89. {
  90. tis >> k;
  91. for (int z=0;z<RESOURCE_QUANTITY;z++)
  92. tis>>k;
  93. }
  94. tis >> k;
  95. for (int i=0;i<RESOURCE_QUANTITY;i++)
  96. {
  97. tis >> k;
  98. startres.push_back(k);
  99. }
  100. tis.close();
  101. for (std::map<int,PlayerState>::iterator i = cgi->state->players.begin(); i!=cgi->state->players.end(); i++)
  102. {
  103. (*i).second.resources.resize(RESOURCE_QUANTITY);
  104. for (int x=0;x<RESOURCE_QUANTITY;x++)
  105. (*i).second.resources[x] = startres[x];
  106. }
  107. /*************************HEROES************************************************/
  108. for (int i=0; i<cgi->heroh->heroInstances.size();i++) //heroes instances
  109. {
  110. if (!cgi->heroh->heroInstances[i]->type || cgi->heroh->heroInstances[i]->owner<0)
  111. continue;
  112. CHeroInstance * vhi = new CHeroInstance();
  113. *vhi=*(cgi->heroh->heroInstances[i]);
  114. if (!vhi->level)
  115. {
  116. vhi->exp=40+rand()%50;
  117. vhi->level = 1;
  118. }
  119. if (vhi->level>1) ;//TODO dodac um dr, ale potrzebne los
  120. if ((!vhi->primSkills.size()) || (vhi->primSkills[0]<0))
  121. {
  122. if (vhi->primSkills.size()<PRIMARY_SKILLS)
  123. vhi->primSkills.resize(PRIMARY_SKILLS);
  124. vhi->primSkills[0] = vhi->type->heroClass->initialAttack;
  125. vhi->primSkills[1] = vhi->type->heroClass->initialDefence;
  126. vhi->primSkills[2] = vhi->type->heroClass->initialPower;
  127. vhi->primSkills[3] = vhi->type->heroClass->initialKnowledge;
  128. vhi->mana = vhi->primSkills[3]*10;
  129. }
  130. if (!vhi->name.length())
  131. {
  132. vhi->name = vhi->type->name;
  133. }
  134. if (!vhi->biography.length())
  135. {
  136. vhi->biography = vhi->type->biography;
  137. }
  138. if (vhi->portrait < 0)
  139. vhi->portrait = vhi->type->ID;
  140. cgi->state->players[vhi->owner].heroes.push_back(vhi);
  141. }
  142. /*************************FOG**OF**WAR******************************************/
  143. for(std::map<int, PlayerState>::iterator k=cgi->state->players.begin(); k!=cgi->state->players.end(); ++k)
  144. {
  145. k->second.fogOfWarMap.resize(cgi->ac->map.width);
  146. for(int g=0; g<cgi->ac->map.width; ++g)
  147. k->second.fogOfWarMap[g].resize(cgi->ac->map.height);
  148. for(int g=0; g<cgi->ac->map.width; ++g)
  149. for(int h=0; h<cgi->ac->map.height; ++h)
  150. k->second.fogOfWarMap[g][h].resize(cgi->ac->map.twoLevel+1);
  151. for(int g=0; g<cgi->ac->map.width; ++g)
  152. for(int h=0; h<cgi->ac->map.height; ++h)
  153. for(int v=0; v<cgi->ac->map.twoLevel+1; ++v)
  154. k->second.fogOfWarMap[g][h][v] = 1;
  155. }
  156. /****************************TOWNS************************************************/
  157. for (int i=0;i<cgi->townh->townInstances.size();i++)
  158. {
  159. CTownInstance * vti = new CTownInstance();
  160. (*vti)=*(cgi->townh->townInstances[i]);
  161. cgi->state->players[vti->owner].towns.push_back(vti);
  162. }
  163. }
  164. int _tmain(int argc, _TCHAR* argv[])
  165. {
  166. int iErr = 0;
  167. lua_State *lua = lua_open (); // Open Lua
  168. LUA_OPEN_LIB(lua, luaopen_base);
  169. LUA_OPEN_LIB(lua, luaopen_io);
  170. if ((iErr = luaL_loadfile (lua, "test.lua")) == 0)
  171. {
  172. // Call main...
  173. if ((iErr = lua_pcall (lua, 0, LUA_MULTRET, 0)) == 0)
  174. {
  175. luabind::open(lua);
  176. luabind::module(lua)
  177. [
  178. luabind::def("powitanie",&piszpowitanie2)
  179. ];
  180. //int ret = luabind::call_function<int>(lua, "helloWorld2");
  181. lua_pushstring (lua, "helloWorld2");
  182. lua_gettable (lua, LUA_GLOBALSINDEX);
  183. lua_pcall (lua, 0, 0, 0);
  184. // Push the function name onto the stack
  185. lua_pushstring (lua, "helloWorld");
  186. lua_gettable (lua, LUA_GLOBALSINDEX);
  187. lua_pcall (lua, 0, 0, 0);
  188. }
  189. }
  190. lua_close (lua);
  191. //CBIKHandler cb;
  192. //cb.open("CSECRET.BIK");
  193. THC timeHandler tmh;
  194. THC tmh.getDif();
  195. int xx=0, yy=0, zz=0;
  196. SDL_Event sEvent;
  197. srand ( time(NULL) );
  198. SDL_Surface *temp;
  199. std::vector<SDL_Surface*> Sprites;
  200. float i;
  201. if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO/*|SDL_INIT_EVENTTHREAD*/)==0)
  202. {
  203. CPG=NULL;
  204. TTF_Init();
  205. atexit(TTF_Quit);
  206. atexit(SDL_Quit);
  207. //TNRB = TTF_OpenFont("Fonts\\tnrb.ttf",16);
  208. TNRB16 = TTF_OpenFont("Fonts\\tnrb.ttf",16);
  209. //TNR = TTF_OpenFont("Fonts\\tnr.ttf",10);
  210. GEOR13 = TTF_OpenFont("Fonts\\georgia.ttf",13);
  211. GEORXX = TTF_OpenFont("Fonts\\tnrb.ttf",22);
  212. GEORM = TTF_OpenFont("Fonts\\georgia.ttf",10);
  213. CMusicHandler * mush = new CMusicHandler; //initializing audio
  214. mush->initMusics();
  215. //audio initialized
  216. /*if(Mix_PlayMusic(mush->mainMenuWoG, -1)==-1) //uncomment this fragment to have music
  217. {
  218. printf("Mix_PlayMusic: %s\n", Mix_GetError());
  219. // well, there's no music, but most games don't break without music...
  220. }*/
  221. screen2 = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/);
  222. screen = SDL_ConvertSurface(screen2, screen2->format, SDL_SWSURFACE);
  223. ekran = screen;
  224. SDL_WM_SetCaption(NAME,""); //set window title
  225. CGameInfo * cgi = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.)
  226. CGameInfo::mainObj = cgi;
  227. cgi->consoleh = new CConsoleHandler;
  228. cgi->mush = mush;
  229. cgi->curh = new CCursorHandler;
  230. THC std::cout<<"Initializing screen, fonts and sound handling: "<<tmh.getDif()<<std::endl;
  231. cgi->spriteh = new CLodHandler;
  232. cgi->spriteh->init(std::string("Data\\H3sprite.lod"));
  233. cgi->bitmaph = new CLodHandler;
  234. cgi->bitmaph->init(std::string("Data\\H3bitmap.lod"));
  235. THC std::cout<<"Loading .lod files: "<<tmh.getDif()<<std::endl;
  236. cgi->curh->initCursor();
  237. cgi->curh->showGraphicCursor();
  238. cgi->screenh = new CScreenHandler;
  239. cgi->screenh->initScreen();
  240. //colors initialization
  241. SDL_Color p;
  242. p.unused = 0;
  243. p.r = 0xff; p.g = 0x0; p.b = 0x0; //red
  244. cgi->playerColors.push_back(p); //red
  245. p.r = 0x31; p.g = 0x52; p.b = 0xff; //blue
  246. cgi->playerColors.push_back(p); //blue
  247. p.r = 0x9c; p.g = 0x73; p.b = 0x52;//tan
  248. cgi->playerColors.push_back(p);//tan
  249. p.r = 0x42; p.g = 0x94; p.b = 0x29; //green
  250. cgi->playerColors.push_back(p); //green
  251. p.r = 0xff; p.g = 0x84; p.b = 0x0; //orange
  252. cgi->playerColors.push_back(p); //orange
  253. p.r = 0x8c; p.g = 0x29; p.b = 0xa5; //purple
  254. cgi->playerColors.push_back(p); //purple
  255. p.r = 0x09; p.g = 0x9c; p.b = 0xa5;//teal
  256. cgi->playerColors.push_back(p);//teal
  257. p.r = 0xc6; p.g = 0x7b; p.b = 0x8c;//pink
  258. cgi->playerColors.push_back(p);//pink
  259. p.r = 0x84; p.g = 0x84; p.b = 0x84;//gray
  260. cgi->neutralColor = p;//gray
  261. //colors initialized
  262. CMessage::init();
  263. cgi->townh = new CTownHandler;
  264. cgi->townh->loadNames();
  265. CAbilityHandler * abilh = new CAbilityHandler;
  266. abilh->loadAbilities();
  267. cgi->abilh = abilh;
  268. CHeroHandler * heroh = new CHeroHandler;
  269. heroh->loadHeroes();
  270. heroh->loadPortraits();
  271. cgi->heroh = heroh;
  272. cgi->generaltexth = new CGeneralTextHandler;
  273. cgi->generaltexth->load();
  274. //initializing hero flags
  275. cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01L.DEF")); //red
  276. cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01G.DEF")); //blue
  277. cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01R.DEF")); //tan
  278. cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01D.DEF")); //green
  279. cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01B.DEF")); //orange
  280. cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01P.DEF")); //purple
  281. cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01W.DEF")); //teal
  282. cgi->heroh->flags1.push_back(cgi->spriteh->giveDef("ABF01K.DEF")); //pink
  283. for(int q=0; q<8; ++q)
  284. {
  285. for(int o=0; o<cgi->heroh->flags1[q]->ourImages.size(); ++o)
  286. {
  287. if(cgi->heroh->flags1[q]->ourImages[o].groupNumber==6)
  288. {
  289. for(int e=0; e<8; ++e)
  290. {
  291. Cimage nci;
  292. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags1[q]->ourImages[o+e].bitmap);
  293. nci.groupNumber = 10;
  294. nci.imName = std::string();
  295. cgi->heroh->flags1[q]->ourImages.push_back(nci);
  296. }
  297. o+=8;
  298. }
  299. if(cgi->heroh->flags1[q]->ourImages[o].groupNumber==7)
  300. {
  301. for(int e=0; e<8; ++e)
  302. {
  303. Cimage nci;
  304. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags1[q]->ourImages[o+e].bitmap);
  305. nci.groupNumber = 11;
  306. nci.imName = std::string();
  307. cgi->heroh->flags1[q]->ourImages.push_back(nci);
  308. }
  309. o+=8;
  310. }
  311. if(cgi->heroh->flags1[q]->ourImages[o].groupNumber==8)
  312. {
  313. for(int e=0; e<8; ++e)
  314. {
  315. Cimage nci;
  316. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags1[q]->ourImages[o+e].bitmap);
  317. nci.groupNumber = 12;
  318. nci.imName = std::string();
  319. cgi->heroh->flags1[q]->ourImages.push_back(nci);
  320. }
  321. o+=8;
  322. }
  323. }
  324. for(int ff=80; ff<cgi->heroh->flags1[q]->ourImages.size(); ++ff)
  325. {
  326. CSDL_Ext::fullAlphaTransform(cgi->heroh->flags1[q]->ourImages[ff].bitmap);
  327. }
  328. cgi->heroh->flags1[q]->alphaTransformed = true;
  329. }
  330. cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02L.DEF")); //red
  331. cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02G.DEF")); //blue
  332. cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02R.DEF")); //tan
  333. cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02D.DEF")); //green
  334. cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02B.DEF")); //orange
  335. cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02P.DEF")); //purple
  336. cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02W.DEF")); //teal
  337. cgi->heroh->flags2.push_back(cgi->spriteh->giveDef("ABF02K.DEF")); //pink
  338. for(int q=0; q<8; ++q)
  339. {
  340. for(int o=0; o<cgi->heroh->flags2[q]->ourImages.size(); ++o)
  341. {
  342. if(cgi->heroh->flags2[q]->ourImages[o].groupNumber==6)
  343. {
  344. for(int e=0; e<8; ++e)
  345. {
  346. Cimage nci;
  347. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags2[q]->ourImages[o+e].bitmap);
  348. nci.groupNumber = 10;
  349. nci.imName = std::string();
  350. cgi->heroh->flags2[q]->ourImages.push_back(nci);
  351. }
  352. o+=8;
  353. }
  354. if(cgi->heroh->flags2[q]->ourImages[o].groupNumber==7)
  355. {
  356. for(int e=0; e<8; ++e)
  357. {
  358. Cimage nci;
  359. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags2[q]->ourImages[o+e].bitmap);
  360. nci.groupNumber = 11;
  361. nci.imName = std::string();
  362. cgi->heroh->flags2[q]->ourImages.push_back(nci);
  363. }
  364. o+=8;
  365. }
  366. if(cgi->heroh->flags2[q]->ourImages[o].groupNumber==8)
  367. {
  368. for(int e=0; e<8; ++e)
  369. {
  370. Cimage nci;
  371. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags2[q]->ourImages[o+e].bitmap);
  372. nci.groupNumber = 12;
  373. nci.imName = std::string();
  374. cgi->heroh->flags2[q]->ourImages.push_back(nci);
  375. }
  376. o+=8;
  377. }
  378. }
  379. for(int ff=80; ff<cgi->heroh->flags2[q]->ourImages.size(); ++ff)
  380. {
  381. CSDL_Ext::fullAlphaTransform(cgi->heroh->flags2[q]->ourImages[ff].bitmap);
  382. }
  383. cgi->heroh->flags2[q]->alphaTransformed = true;
  384. }
  385. cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03L.DEF")); //red
  386. cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03G.DEF")); //blue
  387. cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03R.DEF")); //tan
  388. cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03D.DEF")); //green
  389. cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03B.DEF")); //orange
  390. cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03P.DEF")); //purple
  391. cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03W.DEF")); //teal
  392. cgi->heroh->flags3.push_back(cgi->spriteh->giveDef("ABF03K.DEF")); //pink
  393. for(int q=0; q<8; ++q)
  394. {
  395. for(int o=0; o<cgi->heroh->flags3[q]->ourImages.size(); ++o)
  396. {
  397. if(cgi->heroh->flags3[q]->ourImages[o].groupNumber==6)
  398. {
  399. for(int e=0; e<8; ++e)
  400. {
  401. Cimage nci;
  402. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags3[q]->ourImages[o+e].bitmap);
  403. nci.groupNumber = 10;
  404. nci.imName = std::string();
  405. cgi->heroh->flags3[q]->ourImages.push_back(nci);
  406. }
  407. o+=8;
  408. }
  409. if(cgi->heroh->flags3[q]->ourImages[o].groupNumber==7)
  410. {
  411. for(int e=0; e<8; ++e)
  412. {
  413. Cimage nci;
  414. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags3[q]->ourImages[o+e].bitmap);
  415. nci.groupNumber = 11;
  416. nci.imName = std::string();
  417. cgi->heroh->flags3[q]->ourImages.push_back(nci);
  418. }
  419. o+=8;
  420. }
  421. if(cgi->heroh->flags3[q]->ourImages[o].groupNumber==8)
  422. {
  423. for(int e=0; e<8; ++e)
  424. {
  425. Cimage nci;
  426. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags3[q]->ourImages[o+e].bitmap);
  427. nci.groupNumber = 12;
  428. nci.imName = std::string();
  429. cgi->heroh->flags3[q]->ourImages.push_back(nci);
  430. }
  431. o+=8;
  432. }
  433. }
  434. for(int ff=80; ff<cgi->heroh->flags3[q]->ourImages.size(); ++ff)
  435. {
  436. CSDL_Ext::fullAlphaTransform(cgi->heroh->flags3[q]->ourImages[ff].bitmap);
  437. }
  438. cgi->heroh->flags3[q]->alphaTransformed = true;
  439. }
  440. cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF00.DEF")); //red
  441. cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF01.DEF")); //blue
  442. cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF02.DEF")); //tan
  443. cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF03.DEF")); //green
  444. cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF04.DEF")); //orange
  445. cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF05.DEF")); //purple
  446. cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF06.DEF")); //teal
  447. cgi->heroh->flags4.push_back(cgi->spriteh->giveDef("AF07.DEF")); //pink
  448. for(int q=0; q<8; ++q)
  449. {
  450. for(int o=0; o<cgi->heroh->flags4[q]->ourImages.size(); ++o)
  451. {
  452. if(cgi->heroh->flags4[q]->ourImages[o].groupNumber==6)
  453. {
  454. for(int e=0; e<8; ++e)
  455. {
  456. Cimage nci;
  457. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap);
  458. nci.groupNumber = 10;
  459. nci.imName = std::string();
  460. cgi->heroh->flags4[q]->ourImages.push_back(nci);
  461. }
  462. o+=8;
  463. }
  464. if(cgi->heroh->flags4[q]->ourImages[o].groupNumber==7)
  465. {
  466. for(int e=0; e<8; ++e)
  467. {
  468. Cimage nci;
  469. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap);
  470. nci.groupNumber = 11;
  471. nci.imName = std::string();
  472. cgi->heroh->flags4[q]->ourImages.push_back(nci);
  473. }
  474. o+=8;
  475. }
  476. if(cgi->heroh->flags4[q]->ourImages[o].groupNumber==8)
  477. {
  478. for(int e=0; e<8; ++e)
  479. {
  480. Cimage nci;
  481. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap);
  482. nci.groupNumber = 12;
  483. nci.imName = std::string();
  484. cgi->heroh->flags4[q]->ourImages.push_back(nci);
  485. }
  486. o+=8;
  487. }
  488. }
  489. for(int o=0; o<cgi->heroh->flags4[q]->ourImages.size(); ++o)
  490. {
  491. if(cgi->heroh->flags4[q]->ourImages[o].groupNumber==1)
  492. {
  493. for(int e=0; e<8; ++e)
  494. {
  495. Cimage nci;
  496. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap);
  497. nci.groupNumber = 13;
  498. nci.imName = std::string();
  499. cgi->heroh->flags4[q]->ourImages.push_back(nci);
  500. }
  501. o+=8;
  502. }
  503. if(cgi->heroh->flags4[q]->ourImages[o].groupNumber==2)
  504. {
  505. for(int e=0; e<8; ++e)
  506. {
  507. Cimage nci;
  508. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap);
  509. nci.groupNumber = 14;
  510. nci.imName = std::string();
  511. cgi->heroh->flags4[q]->ourImages.push_back(nci);
  512. }
  513. o+=8;
  514. }
  515. if(cgi->heroh->flags4[q]->ourImages[o].groupNumber==3)
  516. {
  517. for(int e=0; e<8; ++e)
  518. {
  519. Cimage nci;
  520. nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap);
  521. nci.groupNumber = 15;
  522. nci.imName = std::string();
  523. cgi->heroh->flags4[q]->ourImages.push_back(nci);
  524. }
  525. o+=8;
  526. }
  527. }
  528. for(int ff=80; ff<cgi->heroh->flags4[q]->ourImages.size(); ++ff)
  529. {
  530. CSDL_Ext::fullAlphaTransform(cgi->heroh->flags4[q]->ourImages[ff].bitmap);
  531. }
  532. cgi->heroh->flags4[q]->alphaTransformed = true;
  533. }
  534. //hero flags initialized
  535. THC std::cout<<"Preparing first handlers: "<<tmh.getDif()<<std::endl;
  536. CPreGame * cpg = new CPreGame(); //main menu and submenus
  537. THC std::cout<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl;
  538. cpg->mush = mush;
  539. cgi->scenarioOps = cpg->runLoop();
  540. THC tmh.getDif();
  541. cgi->sspriteh = new CSemiLodHandler();
  542. cgi->sspriteh->openLod("H3sprite.lod");
  543. CArtHandler * arth = new CArtHandler;
  544. arth->loadArtifacts();
  545. cgi->arth = arth;
  546. CCreatureHandler * creh = new CCreatureHandler;
  547. creh->loadCreatures();
  548. cgi->creh = creh;
  549. CSpellHandler * spellh = new CSpellHandler;
  550. spellh->loadSpells();
  551. cgi->spellh = spellh;
  552. CBuildingHandler * buildh = new CBuildingHandler;
  553. buildh->loadBuildings();
  554. cgi->buildh = buildh;
  555. CObjectHandler * objh = new CObjectHandler;
  556. objh->loadObjects();
  557. cgi->objh = objh;
  558. cgi->dobjinfo = new CDefObjInfoHandler;
  559. cgi->dobjinfo->load();
  560. cgi->state = new CGameState();
  561. cgi->state->players = std::map<int, PlayerState>();
  562. cgi->pathf = new CPathfinder();
  563. cgi->consoleh->cb = new CCallback(cgi->state,-1);
  564. cgi->consoleh->runConsole();
  565. THC std::cout<<"Handlers initailization: "<<tmh.getDif()<<std::endl;
  566. std::string mapname;
  567. if(CPG->ourScenSel->mapsel.selected==0) CPG->ourScenSel->mapsel.selected = 1; //only for tests
  568. if (CPG) mapname = CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].filename;
  569. gzFile map = gzopen(mapname.c_str(),"rb");
  570. std::string mapstr;int pom;
  571. while((pom=gzgetc(map))>=0)
  572. {
  573. mapstr+=pom;
  574. }
  575. gzclose(map);
  576. unsigned char *initTable = new unsigned char[mapstr.size()];
  577. for(int ss=0; ss<mapstr.size(); ++ss)
  578. {
  579. initTable[ss] = mapstr[ss];
  580. }
  581. #define CHOOSE
  582. #ifdef CHOOSE
  583. CAmbarCendamo * ac = new CAmbarCendamo(initTable); //4gryf
  584. #else
  585. CAmbarCendamo * ac = new CAmbarCendamo("RoEtest"); //4gryf
  586. #endif
  587. CMapHeader * mmhh = new CMapHeader(ac->bufor); //czytanie nag³ówka
  588. cgi->ac = ac;
  589. THC std::cout<<"Reading file: "<<tmh.getDif()<<std::endl;
  590. ac->deh3m();
  591. THC std::cout<<"Detecting file (together): "<<tmh.getDif()<<std::endl;
  592. ac->loadDefs();
  593. THC std::cout<<"Reading terrain defs: "<<tmh.getDif()<<std::endl;
  594. CMapHandler * mh = new CMapHandler();
  595. cgi->mh = mh;
  596. mh->reader = ac;
  597. THC std::cout<<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
  598. mh->init();
  599. THC std::cout<<"Initializing mapHandler: "<<tmh.getDif()<<std::endl;
  600. initGameState(cgi);
  601. THC std::cout<<"Initializing GameState: "<<tmh.getDif()<<std::endl;
  602. for (int i=0; i<cgi->scenarioOps.playerInfos.size();i++) //initializing interfaces
  603. {
  604. //TODO: uncomment when AI will be done
  605. //if(cgi->scenarioOps.playerInfos[i].name=="AI")
  606. // cgi->playerint.push_back(new CGlobalAI());
  607. //else
  608. {
  609. cgi->state->currentPlayer=cgi->scenarioOps.playerInfos[i].color;
  610. cgi->playerint.push_back(new CPlayerInterface(cgi->scenarioOps.playerInfos[i].color,i));
  611. ((CPlayerInterface*)(cgi->playerint[i]))->init(new CCallback(cgi->state,cgi->scenarioOps.playerInfos[i].color));
  612. }
  613. }
  614. while(1) //main game loop, one execution per turn
  615. {
  616. cgi->consoleh->cb->newTurn();
  617. for (int i=0;i<cgi->playerint.size();i++)
  618. {
  619. cgi->state->currentPlayer=cgi->playerint[i]->playerID;
  620. cgi->playerint[i]->yourTurn();
  621. }
  622. }
  623. }
  624. else
  625. {
  626. printf("Something was wrong: %s/n", SDL_GetError());
  627. return -1;
  628. }
  629. }