CMT.cpp 21 KB

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