CMT.cpp 23 KB

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