Graphics.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. #include "../stdafx.h"
  2. #include "Graphics.h"
  3. #include "../hch/CDefHandler.h"
  4. #include "../hch/CObjectHandler.h"
  5. #include "../SDL_Extensions.h"
  6. #include <boost/assign/std/vector.hpp>
  7. #include <sstream>
  8. #include <iomanip>
  9. #include <boost/thread.hpp>
  10. #include <boost/function.hpp>
  11. #include <boost/bind.hpp>
  12. #include <boost/assign/std/vector.hpp>
  13. #include "../CThreadHelper.h"
  14. #include "../CGameInfo.h"
  15. #include "../hch/CLodHandler.h"
  16. #include "../lib/VCMI_Lib.h"
  17. using namespace boost::assign;
  18. using namespace CSDL_Ext;
  19. #ifdef min
  20. #undef min
  21. #endif
  22. #ifdef max
  23. #undef max
  24. #endif
  25. /*
  26. * Graphics.cpp, part of VCMI engine
  27. *
  28. * Authors: listed in file AUTHORS in main folder
  29. *
  30. * License: GNU General Public License v2.0 or later
  31. * Full text of license available in license.txt file, in main folder
  32. *
  33. */
  34. Graphics * graphics = NULL;
  35. SDL_Surface * Graphics::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to)
  36. {
  37. char buf[10];
  38. for (int i=from;i<to;i++)
  39. {
  40. SDL_itoa(curh->getPrimSkillLevel(i),buf,10);
  41. printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
  42. }
  43. return ret;
  44. }
  45. SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh)
  46. {
  47. char buf[10];
  48. blueToPlayersAdv(hInfo,curh->tempOwner);
  49. SDL_Surface * ret = SDL_DisplayFormat(hInfo);
  50. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  51. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  52. drawPrimarySkill(curh, ret);
  53. for (std::map<si32,std::pair<ui32,si32> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  54. {
  55. blitAt(graphics->smallImgs[(*i).second.first],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  56. SDL_itoa((*i).second.second,buf,10);
  57. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  58. }
  59. blitAt(graphics->portraitLarge[curh->portrait],11,12,ret);
  60. SDL_itoa(curh->mana,buf,10);
  61. printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
  62. blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
  63. blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
  64. return ret;
  65. }
  66. SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh)
  67. {
  68. char buf[10];
  69. blueToPlayersAdv(tInfo,curh->tempOwner);
  70. SDL_Surface * ret = SDL_DisplayFormat(tInfo);
  71. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  72. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  73. int pom = curh->fortLevel() - 1; if(pom<0) pom = 3;
  74. blitAt(forts->ourImages[pom].bitmap,115,42,ret);
  75. if((pom=curh->hallLevel())>=0)
  76. blitAt(halls->ourImages[pom].bitmap,77,42,ret);
  77. SDL_itoa(curh->dailyIncome(),buf,10);
  78. printAtMiddle(buf,167,70,GEORM,zwykly,ret);
  79. for (std::map<si32,std::pair<ui32,si32> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  80. {
  81. if(!i->second.second)
  82. continue;
  83. blitAt(graphics->smallImgs[(*i).second.first],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  84. SDL_itoa((*i).second.second,buf,10);
  85. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  86. }
  87. //blit town icon
  88. pom = curh->subID*2;
  89. if (!curh->hasFort())
  90. pom += F_NUMBER*2;
  91. if(curh->builded >= MAX_BUILDING_PER_TURN)
  92. pom++;
  93. if(curh->garrisonHero)
  94. blitAt(graphics->heroInGarrison,158,87,ret);
  95. blitAt(bigTownPic->ourImages[pom].bitmap,13,13,ret);
  96. return ret;
  97. }
  98. void Graphics::loadPaletteAndColors()
  99. {
  100. std::string pals = bitmaph->getTextFile("PLAYERS.PAL");
  101. playerColorPalette = new SDL_Color[256];
  102. neutralColor = new SDL_Color;
  103. playerColors = new SDL_Color[PLAYER_LIMIT];
  104. int startPoint = 24; //beginning byte; used to read
  105. for(int i=0; i<256; ++i)
  106. {
  107. SDL_Color col;
  108. col.r = pals[startPoint++];
  109. col.g = pals[startPoint++];
  110. col.b = pals[startPoint++];
  111. col.unused = pals[startPoint++];
  112. playerColorPalette[i] = col;
  113. }
  114. //colors initialization
  115. int3 kolory[] = {int3(0xff,0,0),int3(0x31,0x52,0xff),int3(0x9c,0x73,0x52),int3(0x42,0x94,0x29),
  116. int3(0xff,0x84,0x0),int3(0x8c,0x29,0xa5),int3(0x09,0x9c,0xa5),int3(0xc6,0x7b,0x8c)};
  117. for(int i=0;i<8;i++)
  118. {
  119. playerColors[i].r = kolory[i].x;
  120. playerColors[i].g = kolory[i].y;
  121. playerColors[i].b = kolory[i].z;
  122. playerColors[i].unused = 0;
  123. }
  124. neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84; neutralColor->unused = 0x0;//gray
  125. std::ifstream bback("config/mageBg.txt");
  126. while(!bback.eof())
  127. {
  128. bback >> pals;
  129. guildBgs.push_back(pals);
  130. }
  131. bback.close();
  132. }
  133. void Graphics::initializeBattleGraphics()
  134. {
  135. std::ifstream bback("config/battleBack.txt");
  136. battleBacks.resize(26);
  137. for(int i=1; i<26; ++i) //25 - number of terrains battle can be fought on
  138. {
  139. int am;
  140. bback>>am;
  141. battleBacks[i].resize(am);
  142. for(int f=0; f<am; ++f)
  143. {
  144. bback>>battleBacks[i][f];
  145. }
  146. }
  147. //initializing battle hero animation
  148. std::ifstream bher("config/battleHeroes.txt");
  149. int numberofh;
  150. bher>>numberofh;
  151. battleHeroes.resize(numberofh);
  152. for(int i=0; i<numberofh; ++i) //9 - number of terrains battle can be fought on
  153. {
  154. bher>>battleHeroes[i];
  155. }
  156. //initialization of AC->def name mapping
  157. std::ifstream acd;
  158. acd.open("config/AC_desc.txt", std::ios::binary);
  159. if(!acd.is_open())
  160. {
  161. tlog1<<"lack of config/AC_desc.txt file!"<<std::endl;
  162. }
  163. else
  164. {
  165. std::string buf;
  166. acd>>buf;
  167. int ACid, numberOfDefs;
  168. while(true)
  169. {
  170. std::vector< std::string > toAdd;
  171. acd>>ACid;
  172. if(ACid == -1)
  173. break;
  174. acd>>numberOfDefs;
  175. for(int g=0; g<numberOfDefs; ++g)
  176. {
  177. acd>>buf;
  178. toAdd.push_back(buf);
  179. }
  180. battleACToDef[ACid] = toAdd;
  181. }
  182. }
  183. spellEffectsPics = CDefHandler::giveDef("SpellInt.def");
  184. }
  185. Graphics::Graphics()
  186. {
  187. slotsPos.push_back(std::pair<int,int>(44,82));
  188. slotsPos.push_back(std::pair<int,int>(80,82));
  189. slotsPos.push_back(std::pair<int,int>(116,82));
  190. slotsPos.push_back(std::pair<int,int>(26,131));
  191. slotsPos.push_back(std::pair<int,int>(62,131));
  192. slotsPos.push_back(std::pair<int,int>(98,131));
  193. slotsPos.push_back(std::pair<int,int>(134,131));
  194. CDefHandler *smi, *smi2;
  195. std::vector<Task> tasks; //preparing list of graphics to load
  196. tasks += boost::bind(&Graphics::loadPaletteAndColors,this);
  197. tasks += boost::bind(&Graphics::loadHeroFlags,this);
  198. tasks += boost::bind(&Graphics::loadHeroPortraits,this);
  199. tasks += boost::bind(&Graphics::initializeBattleGraphics,this);
  200. tasks += GET_SURFACE(hInfo,"HEROQVBK.bmp");
  201. tasks += GET_SURFACE(tInfo,"TOWNQVBK.bmp");
  202. tasks += GET_SURFACE(heroInGarrison,"TOWNQKGH.bmp");
  203. tasks += GET_DEF(artDefs,"ARTIFACT.DEF");
  204. tasks += GET_DEF_ESS(forts,"ITMCLS.DEF");
  205. tasks += GET_DEF_ESS(luck22,"ILCK22.DEF");
  206. tasks += GET_DEF_ESS(luck30,"ILCK30.DEF");
  207. tasks += GET_DEF_ESS(luck42,"ILCK42.DEF");
  208. tasks += GET_DEF_ESS(luck82,"ILCK82.DEF");
  209. tasks += GET_DEF_ESS(morale22,"IMRL22.DEF");
  210. tasks += GET_DEF_ESS(morale30,"IMRL30.DEF");
  211. tasks += GET_DEF_ESS(morale42,"IMRL42.DEF");
  212. tasks += GET_DEF_ESS(morale82,"IMRL82.DEF");
  213. tasks += GET_DEF_ESS(halls,"ITMTLS.DEF");
  214. tasks += GET_DEF_ESS(bigTownPic,"ITPT.DEF");
  215. tasks += GET_DEF(pskillsb,"PSKILL.DEF");
  216. tasks += GET_DEF(pskillsm,"PSKIL42.DEF");
  217. tasks += GET_DEF(resources,"RESOUR82.DEF");
  218. tasks += GET_DEF(un44,"UN44.DEF");
  219. tasks += GET_DEF(smallIcons,"ITPA.DEF");
  220. tasks += GET_DEF(resources32,"RESOURCE.DEF");
  221. tasks += GET_DEF(smi,"CPRSMALL.DEF");
  222. tasks += GET_DEF(smi2,"TWCRPORT.DEF");
  223. tasks += GET_DEF(flags,"CREST58.DEF");
  224. tasks += GET_DEF(abils32,"SECSK32.DEF");
  225. tasks += GET_DEF(abils44,"SECSKILL.DEF");
  226. tasks += GET_DEF(abils82,"SECSK82.DEF");
  227. tasks += GET_DEF(spellscr,"SPELLSCR.DEF");
  228. std::ifstream ifs("config/cr_bgs.txt");
  229. int id;
  230. std::string name;
  231. while(!ifs.eof())
  232. {
  233. ifs >> id >> name;
  234. tasks += GET_SURFACE(backgrounds[id],name);
  235. name.replace(0,5,"TPCAS");
  236. tasks += GET_SURFACE(backgroundsm[id],name);
  237. }
  238. CThreadHelper th(&tasks,std::max((unsigned int)1,boost::thread::hardware_concurrency()));
  239. th.run();
  240. //handling 32x32px imgs
  241. smi->notFreeImgs = true;
  242. for (size_t i=0; i<smi->ourImages.size(); ++i)
  243. {
  244. smallImgs[i-2] = smi->ourImages[i].bitmap;
  245. }
  246. delete smi;
  247. smi2->notFreeImgs = true;
  248. for (size_t i=0; i<smi2->ourImages.size(); ++i)
  249. {
  250. bigImgs[i-2] = smi2->ourImages[i].bitmap;
  251. }
  252. delete smi2;
  253. }
  254. void Graphics::loadHeroPortraits()
  255. {
  256. std::ifstream of("config/portrety.txt");
  257. int numberOfPortraits;
  258. of>>numberOfPortraits;
  259. for (int j=0; j<numberOfPortraits; j++)
  260. {
  261. int ID;
  262. of>>ID;
  263. std::string path;
  264. of>>path;
  265. portraitSmall.push_back(BitmapHandler::loadBitmap(path));
  266. for(size_t ff=0; ff<path.size(); ++ff) //size letter is usually third one, but there are exceptions an it should fix the problem
  267. {
  268. if(path[ff]=='S')
  269. {
  270. path[ff]='L';
  271. break;
  272. }
  273. }
  274. portraitLarge.push_back(BitmapHandler::loadBitmap(path));
  275. SDL_SetColorKey(portraitLarge[portraitLarge.size()-1],SDL_SRCCOLORKEY,SDL_MapRGB(portraitLarge[portraitLarge.size()-1]->format,0,255,255));
  276. }
  277. of.close();
  278. }
  279. void Graphics::loadHeroAnim()
  280. {
  281. heroAnims.resize(F_NUMBER * 2);
  282. std::vector<std::pair<int,int> > rotations; //first - group number to be rotated1, second - group number after rotation1
  283. rotations += std::make_pair(6,10), std::make_pair(7,11), std::make_pair(8,12), std::make_pair(1,13),
  284. std::make_pair(2,14), std::make_pair(3,15);
  285. for(size_t i=0; i<heroAnims.size(); ++i)
  286. {
  287. std::stringstream nm;
  288. nm << "AH" << std::setw(2) << std::setfill('0') << i << "_.DEF";
  289. std::string name = nm.str();
  290. heroAnims[i] = CDefHandler::giveDef(name);
  291. int pom = 0; //how many groups has been rotated
  292. for(int o=7; pom<6; ++o)
  293. {
  294. for(int p=0;p<6;p++)
  295. {
  296. if(heroAnims[i]->ourImages[o].groupNumber==rotations[p].first)
  297. {
  298. for(int e=0; e<8; ++e)
  299. {
  300. Cimage nci;
  301. nci.bitmap = CSDL_Ext::rotate01(heroAnims[i]->ourImages[o+e].bitmap);
  302. nci.groupNumber = rotations[p].second;
  303. nci.imName = std::string();
  304. heroAnims[i]->ourImages.push_back(nci);
  305. if(pom>2) //we need only one frame for groups 13/14/15
  306. break;
  307. }
  308. if(pom<3) //there are eight frames of animtion of groups 6/7/8 so for speed we'll skip them
  309. o+=8;
  310. else //there is only one frame of 1/2/3
  311. o+=1;
  312. ++pom;
  313. if(p==2 && pom<4) //group1 starts at index 1
  314. o = 1;
  315. }
  316. }
  317. }
  318. for(size_t ff=0; ff<heroAnims[i]->ourImages.size(); ++ff)
  319. {
  320. CSDL_Ext::alphaTransform(heroAnims[i]->ourImages[ff].bitmap);
  321. }
  322. heroAnims[i]->alphaTransformed = true;
  323. }
  324. }
  325. void Graphics::loadHeroFlags(std::pair<std::vector<CDefHandler *> Graphics::*, std::vector<const char *> > &pr, bool mode)
  326. {
  327. for(int i=0;i<8;i++)
  328. (this->*pr.first).push_back(CDefHandler::giveDef(pr.second[i]));
  329. std::vector<std::pair<int,int> > rotations; //first - group number to be rotated1, second - group number after rotation1
  330. rotations += std::make_pair(6,10), std::make_pair(7,11), std::make_pair(8,12);
  331. for(int q=0; q<8; ++q)
  332. {
  333. for(size_t o=0; o<(this->*pr.first)[q]->ourImages.size(); ++o)
  334. {
  335. for(size_t p=0;p<rotations.size();p++)
  336. {
  337. if((this->*pr.first)[q]->ourImages[o].groupNumber==rotations[p].first)
  338. {
  339. for(int e=0; e<8; ++e)
  340. {
  341. Cimage nci;
  342. nci.bitmap = CSDL_Ext::rotate01((this->*pr.first)[q]->ourImages[o+e].bitmap);
  343. nci.groupNumber = rotations[p].second;
  344. nci.imName = std::string();
  345. (this->*pr.first)[q]->ourImages.push_back(nci);
  346. }
  347. o+=8;
  348. }
  349. }
  350. }
  351. if (mode)
  352. {
  353. for(size_t o=0; o<flags4[q]->ourImages.size(); ++o)
  354. {
  355. if(flags4[q]->ourImages[o].groupNumber==1)
  356. {
  357. for(int e=0; e<8; ++e)
  358. {
  359. Cimage nci;
  360. nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
  361. nci.groupNumber = 13;
  362. nci.imName = std::string();
  363. flags4[q]->ourImages.push_back(nci);
  364. }
  365. o+=8;
  366. }
  367. if(flags4[q]->ourImages[o].groupNumber==2)
  368. {
  369. for(int e=0; e<8; ++e)
  370. {
  371. Cimage nci;
  372. nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
  373. nci.groupNumber = 14;
  374. nci.imName = std::string();
  375. flags4[q]->ourImages.push_back(nci);
  376. }
  377. o+=8;
  378. }
  379. if(flags4[q]->ourImages[o].groupNumber==3)
  380. {
  381. for(int e=0; e<8; ++e)
  382. {
  383. Cimage nci;
  384. nci.bitmap = CSDL_Ext::rotate01(flags4[q]->ourImages[o+e].bitmap);
  385. nci.groupNumber = 15;
  386. nci.imName = std::string();
  387. flags4[q]->ourImages.push_back(nci);
  388. }
  389. o+=8;
  390. }
  391. }
  392. }
  393. for(size_t ff=0; ff<(this->*pr.first)[q]->ourImages.size(); ++ff)
  394. {
  395. SDL_SetColorKey((this->*pr.first)[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
  396. SDL_MapRGB((this->*pr.first)[q]->ourImages[ff].bitmap->format, 0, 255, 255)
  397. );
  398. }
  399. (this->*pr.first)[q]->alphaTransformed = true;
  400. }
  401. }
  402. void Graphics::loadHeroFlags()
  403. {
  404. using namespace boost::assign;
  405. timeHandler th;
  406. std::pair<std::vector<CDefHandler *> Graphics::*, std::vector<const char *> > pr[4];
  407. pr[0].first = &Graphics::flags1;
  408. pr[0].second+=("ABF01L.DEF"),("ABF01G.DEF"),("ABF01R.DEF"),("ABF01D.DEF"),("ABF01B.DEF"),
  409. ("ABF01P.DEF"),("ABF01W.DEF"),("ABF01K.DEF");
  410. pr[1].first = &Graphics::flags2;
  411. pr[1].second+=("ABF02L.DEF"),("ABF02G.DEF"),("ABF02R.DEF"),("ABF02D.DEF"),("ABF02B.DEF"),
  412. ("ABF02P.DEF"),("ABF02W.DEF"),("ABF02K.DEF");
  413. pr[2].first = &Graphics::flags3;
  414. pr[2].second+=("ABF03L.DEF"),("ABF03G.DEF"),("ABF03R.DEF"),("ABF03D.DEF"),("ABF03B.DEF"),
  415. ("ABF03P.DEF"),("ABF03W.DEF"),("ABF03K.DEF");
  416. pr[3].first = &Graphics::flags4;
  417. pr[3].second+=("AF00.DEF"),("AF01.DEF"),("AF02.DEF"),("AF03.DEF"),("AF04.DEF"),
  418. ("AF05.DEF"),("AF06.DEF"),("AF07.DEF");
  419. boost::thread_group grupa;
  420. grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[3]),true));
  421. grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[2]),false));
  422. grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[1]),false));
  423. grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[0]),false));
  424. grupa.join_all();
  425. tlog0 << "Loading and transforming heroes' flags: "<<th.getDif()<<std::endl;
  426. }
  427. SDL_Surface * Graphics::getPic(int ID, bool fort, bool builded)
  428. {
  429. if (ID==-1)
  430. return smallIcons->ourImages[0].bitmap;
  431. else if (ID==-2)
  432. return smallIcons->ourImages[1].bitmap;
  433. else if (ID==-3)
  434. return smallIcons->ourImages[2+F_NUMBER*4].bitmap;
  435. else if (ID>F_NUMBER || ID<-3)
  436. #ifndef __GNUC__
  437. throw new std::exception("Invalid ID");
  438. #else
  439. throw new std::exception();
  440. #endif
  441. else
  442. {
  443. int pom = 3;
  444. if(!fort)
  445. pom+=F_NUMBER*2;
  446. pom += ID*2;
  447. if (!builded)
  448. pom--;
  449. return smallIcons->ourImages[pom].bitmap;
  450. }
  451. }
  452. void Graphics::blueToPlayersAdv(SDL_Surface * sur, int player)
  453. {
  454. if(player==1) //it is actually blue...
  455. return;
  456. if(sur->format->BitsPerPixel == 8)
  457. {
  458. for(int i=0; i<32; ++i)
  459. {
  460. sur->format->palette->colors[224+i] = playerColorPalette[32*player+i];
  461. }
  462. }
  463. else if(sur->format->BitsPerPixel == 24) //should never happen in general
  464. {
  465. for(int y=0; y<sur->h; ++y)
  466. {
  467. for(int x=0; x<sur->w; ++x)
  468. {
  469. Uint8* cp = (Uint8*)sur->pixels + y*sur->pitch + x*3;
  470. if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
  471. {
  472. if(cp[2]>cp[1] && cp[2]>cp[0])
  473. {
  474. std::vector<long long int> sort1;
  475. sort1.push_back(cp[0]);
  476. sort1.push_back(cp[1]);
  477. sort1.push_back(cp[2]);
  478. std::vector< std::pair<long long int, Uint8*> > sort2;
  479. sort2.push_back(std::make_pair(graphics->playerColors[player].r, &(cp[0])));
  480. sort2.push_back(std::make_pair(graphics->playerColors[player].g, &(cp[1])));
  481. sort2.push_back(std::make_pair(graphics->playerColors[player].b, &(cp[2])));
  482. std::sort(sort1.begin(), sort1.end());
  483. if(sort2[0].first>sort2[1].first)
  484. std::swap(sort2[0], sort2[1]);
  485. if(sort2[1].first>sort2[2].first)
  486. std::swap(sort2[1], sort2[2]);
  487. if(sort2[0].first>sort2[1].first)
  488. std::swap(sort2[0], sort2[1]);
  489. for(int hh=0; hh<3; ++hh)
  490. {
  491. (*sort2[hh].second) = (sort1[hh] + sort2[hh].first)/2.2;
  492. }
  493. }
  494. }
  495. else
  496. {
  497. if(
  498. (/*(mode==0) && (cp[0]>cp[1]) && (cp[0]>cp[2])) ||
  499. ((mode==1) &&*/ (cp[2]<45) && (cp[0]>80) && (cp[1]<70) && ((cp[0]-cp[1])>40))
  500. )
  501. {
  502. std::vector<long long int> sort1;
  503. sort1.push_back(cp[2]);
  504. sort1.push_back(cp[1]);
  505. sort1.push_back(cp[0]);
  506. std::vector< std::pair<long long int, Uint8*> > sort2;
  507. sort2.push_back(std::make_pair(graphics->playerColors[player].r, &(cp[2])));
  508. sort2.push_back(std::make_pair(graphics->playerColors[player].g, &(cp[1])));
  509. sort2.push_back(std::make_pair(graphics->playerColors[player].b, &(cp[0])));
  510. std::sort(sort1.begin(), sort1.end());
  511. if(sort2[0].first>sort2[1].first)
  512. std::swap(sort2[0], sort2[1]);
  513. if(sort2[1].first>sort2[2].first)
  514. std::swap(sort2[1], sort2[2]);
  515. if(sort2[0].first>sort2[1].first)
  516. std::swap(sort2[0], sort2[1]);
  517. for(int hh=0; hh<3; ++hh)
  518. {
  519. (*sort2[hh].second) = (sort1[hh]*0.8 + sort2[hh].first)/2;
  520. }
  521. }
  522. }
  523. }
  524. }
  525. }
  526. }