1 // Copyright (C) 2003, 2004, 2005, 2006, 2007 Ulf Lorenz
2 // Copyright (C) 2004, 2005, 2006 Andrea Paternesi
3 // Copyright (C) 2006, 2007, 2008, 2009 Ben Asselstine
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Library General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include "rectangle.h"
25 #include "GraphicsCache.h"
26 #include "armysetlist.h"
27 #include "shieldsetlist.h"
28 #include "tilesetlist.h"
29 #include "citysetlist.h"
32 #include "playerlist.h"
33 #include "Configuration.h"
38 #include "gui/image-helpers.h"
42 //#define debug(x) {std::cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<std::endl<<std::flush;}
45 //some structures first
47 //this structure is the base class for storing cached objects. It stores the
48 //(army-, but can be extended) set, the type of army and the player which the
49 //surface is designed for (and the surface itself, of course).
59 bool operator <(ArmyCacheItem lhs, ArmyCacheItem rhs)
61 return memcmp(&lhs, &rhs, sizeof (ArmyCacheItem) - sizeof (PixMask*)) < 0;
64 //the structure to store ships in
72 //the structure to store planted standard in
73 struct PlantedStandardCacheItem
80 //the structure to store new level pictures in
81 struct NewLevelCacheItem
88 //the structure to store temples in
89 struct TempleCacheItem
96 //the structure to store ruins in
104 //the structure to store diplomacy icons in
105 struct DiplomacyCacheItem
108 Player::DiplomaticState state;
112 //the structure to store roads in
120 //the structure to store fog patterns in
127 bool operator <(FogCacheItem lhs, FogCacheItem rhs)
129 return memcmp(&lhs, &rhs, sizeof (FogCacheItem) - sizeof (PixMask*)) < 0;
132 //the structure to store bridges in
133 struct BridgeCacheItem
140 //the structure to store cursors in
141 struct CursorCacheItem
147 //the structure to store buildings in
156 //the structure to store towers in
157 struct TowerCacheItem
164 // the structure to store flags in
173 // the structure to store selector images in
174 struct SelectorCacheItem
183 // the structure to store shield images in
184 struct ShieldCacheItem
192 // the structure to store production shield images in
193 struct ProdShieldCacheItem
200 // the structure to store movement bonus images in
201 struct MoveBonusCacheItem
203 guint32 type; // 0=empty, 1=trees, 2=foothills, 3=hills+trees, 4=fly, 5=boat
207 // the structure to store drawn bigmap tiles in
214 int standard_player_id;
215 int stack_size; //flag size
220 Maptile::Building building_type;
221 int building_subtype;
222 Vector<int> building_tile;
223 int building_player_id;
237 struct SignpostCacheItem
249 struct ExplosionCacheItem
255 bool operator <(TileCacheItem lhs, TileCacheItem rhs)
257 return memcmp(&lhs, &rhs, sizeof (TileCacheItem) - sizeof (PixMask*)) < 0;
259 //-----------------------------------------------------
261 GraphicsCache* GraphicsCache::s_instance = 0;
263 GraphicsCache* GraphicsCache::getInstance()
266 s_instance = new GraphicsCache();
271 void GraphicsCache::deleteInstance()
280 GraphicsCache::GraphicsCache()
291 d_smallruinedcity = getMiscPicture("smallruinedcity.png");
292 d_smallhero = getMiscPicture("hero.png");
293 d_smallinactivehero = getMiscPicture("hero-inactive.png");
294 d_small_ruin_unexplored = getMiscPicture("smallunexploredruin.png");
295 d_small_stronghold_unexplored =
296 getMiscPicture("smallunexploredstronghold.png");
297 d_small_ruin_explored = getMiscPicture("smallexploredruin.png");
298 d_small_temple = getMiscPicture("smalltemple.png");
301 GraphicsCache::~GraphicsCache()
305 for (unsigned int i = 0; i < PRODUCTION_SHIELD_TYPES; i++)
307 delete d_prodshieldpic[i];
310 for (unsigned int i = 0; i < MOVE_BONUS_TYPES; i++)
312 delete d_movebonuspic[i];
315 delete d_smallruinedcity;
317 delete d_smallinactivehero;
318 delete d_small_temple;
319 delete d_small_ruin_unexplored;
320 delete d_small_stronghold_unexplored;
321 delete d_small_ruin_explored;
322 delete d_newlevel_male;
323 delete d_newlevel_female;
324 delete d_newlevelmask_male;
325 delete d_newlevelmask_female;
328 PixMask* GraphicsCache::getSmallRuinedCityPic()
330 return d_smallruinedcity;
333 PixMask* GraphicsCache::getSmallHeroPic(bool active)
338 return d_smallinactivehero;
341 PixMask* GraphicsCache::getSmallRuinExploredPic()
343 return d_small_ruin_explored;
345 PixMask* GraphicsCache::getSmallRuinUnexploredPic()
347 return d_small_ruin_unexplored;
349 PixMask* GraphicsCache::getSmallStrongholdUnexploredPic()
351 return d_small_stronghold_unexplored;
353 PixMask* GraphicsCache::getSmallTemplePic()
355 return d_small_temple;
358 PixMask* GraphicsCache::getMoveBonusPic(guint32 bonus, bool has_ship)
361 if (bonus == Tile::isFlying()) // show fly icon
363 else if (bonus & Tile::FOREST && bonus & Tile::HILLS) // show trees and hills
365 else if (bonus & Tile::HILLS) // show foothills
367 else if (bonus & Tile::FOREST) // show trees
369 else if (has_ship) // (what a) show boat
373 debug("GraphicsCache::getMoveBonusPic " <<bonus <<"," <<type)
375 std::list<MoveBonusCacheItem*>::iterator it;
376 MoveBonusCacheItem* myitem;
378 for (it = d_movebonuslist.begin(); it != d_movebonuslist.end(); it++)
380 if ((*it)->type == type)
384 //put the item in last place (last touched)
385 d_movebonuslist.erase(it);
386 d_movebonuslist.push_back(myitem);
388 return myitem->surface;
392 //no item found -> create a new one
393 myitem = addMoveBonusPic(type);
395 return myitem->surface;
398 PixMask* GraphicsCache::getShipPic(const Player* p)
400 debug("getting ship pic " <<p->getName())
401 std::list<ShipCacheItem*>::iterator it;
402 ShipCacheItem* myitem;
403 for (it = d_shiplist.begin(); it != d_shiplist.end(); it++)
405 if ((*it)->player_id == p->getId() && (*it)->armyset == p->getArmyset())
409 // put the item on the last place (==last touched)
410 d_shiplist.erase(it);
411 d_shiplist.push_back(myitem);
413 return myitem->surface;
416 // We are still here, so the graphic is not in the cache. addShipPic calls
417 // checkPictures on its own, so we can simply return the surface
418 myitem = addShipPic(p);
420 return myitem->surface;
423 PixMask* GraphicsCache::getNewLevelPic(const Player* p, guint32 gender)
425 debug("getting new level pic " <<p->getName())
426 std::list<NewLevelCacheItem*>::iterator it;
427 NewLevelCacheItem* myitem;
428 for (it = d_newlevellist.begin(); it != d_newlevellist.end(); it++)
430 if ((*it)->player_id == p->getId() && (*it)->gender == gender)
434 // put the item on the last place (==last touched)
435 d_newlevellist.erase(it);
436 d_newlevellist.push_back(myitem);
438 return myitem->surface;
441 // We are still here, so the graphic is not in the cache.
442 // addNewLevelPic calls checkPictures on its own, so we can
443 // simply return the surface
444 myitem = addNewLevelPic(p, gender);
446 return myitem->surface;
449 PixMask* GraphicsCache::getPortPic()
451 return getPortPic(GameMap::getInstance()->getCityset()->getId());
454 PixMask* GraphicsCache::getPortPic(guint32 cityset)
456 debug("getting port pic " << cityset)
457 std::list<PortCacheItem*>::iterator it;
458 PortCacheItem* myitem;
459 for (it = d_portlist.begin(); it != d_portlist.end(); it++)
461 if ((*it)->cityset == cityset)
465 // put the item on the last place (==last touched)
466 d_portlist.erase(it);
467 d_portlist.push_back(myitem);
469 return myitem->surface;
472 // We are still here, so the graphic is not in the cache.
473 // addPortPic calls checkPictures on its own, so we can
474 // simply return the surface
475 myitem = addPortPic(cityset);
477 return myitem->surface;
480 PixMask* GraphicsCache::getSignpostPic()
482 return getSignpostPic(GameMap::getInstance()->getCityset()->getId());
485 PixMask* GraphicsCache::getSignpostPic(guint32 cityset)
487 debug("getting signpost pic " << cityset)
488 std::list<SignpostCacheItem*>::iterator it;
489 SignpostCacheItem* myitem;
490 for (it = d_signpostlist.begin(); it != d_signpostlist.end(); it++)
492 if ((*it)->cityset == cityset)
496 // put the item on the last place (==last touched)
497 d_signpostlist.erase(it);
498 d_signpostlist.push_back(myitem);
500 return myitem->surface;
503 // We are still here, so the graphic is not in the cache.
504 // addSignpostPic calls checkPictures on its own, so we can
505 // simply return the surface
506 myitem = addSignpostPic(cityset);
508 return myitem->surface;
511 PixMask* GraphicsCache::getBagPic()
513 guint32 armyset = Playerlist::getActiveplayer()->getArmyset();
514 return getBagPic(armyset);
517 PixMask* GraphicsCache::getBagPic(guint32 armyset)
519 debug("getting bag pic " << armyset)
520 std::list<BagCacheItem*>::iterator it;
521 BagCacheItem* myitem;
522 for (it = d_baglist.begin(); it != d_baglist.end(); it++)
524 if ((*it)->armyset == armyset)
528 // put the item on the last place (==last touched)
530 d_baglist.push_back(myitem);
532 return myitem->surface;
535 // We are still here, so the graphic is not in the cache.
536 // addBagPic calls checkPictures on its own, so we can
537 // simply return the surface
538 myitem = addBagPic(armyset);
540 return myitem->surface;
543 PixMask* GraphicsCache::getExplosionPic()
545 return getExplosionPic(GameMap::getInstance()->getTileset()->getId());
548 PixMask* GraphicsCache::getExplosionPic(guint32 tileset)
550 debug("getting explosion pic " << tileset)
551 std::list<ExplosionCacheItem*>::iterator it;
552 ExplosionCacheItem* myitem;
553 for (it = d_explosionlist.begin(); it != d_explosionlist.end(); it++)
555 if ((*it)->tileset == tileset)
559 // put the item on the last place (==last touched)
560 d_explosionlist.erase(it);
561 d_explosionlist.push_back(myitem);
563 return myitem->surface;
566 // We are still here, so the graphic is not in the cache.
567 // addExplosionPic calls checkPictures on its own, so we can
568 // simply return the surface
569 myitem = addExplosionPic(tileset);
571 return myitem->surface;
574 PixMask* GraphicsCache::getPlantedStandardPic(const Player* p)
576 debug("getting planted standard pic " <<p->getName())
577 std::list<PlantedStandardCacheItem*>::iterator it;
578 PlantedStandardCacheItem* myitem;
579 for (it = d_plantedstandardlist.begin(); it != d_plantedstandardlist.end(); it++)
581 if ((*it)->player_id == p->getId() && (*it)->armyset == p->getArmyset())
585 // put the item on the last place (==last touched)
586 d_plantedstandardlist.erase(it);
587 d_plantedstandardlist.push_back(myitem);
589 return myitem->surface;
592 // We are still here, so the graphic is not in the cache.
593 // addPlantedStandardPic calls checkPictures on its own, so we can
594 // simply return the surface
595 myitem = addPlantedStandardPic(p);
597 return myitem->surface;
600 PixMask* GraphicsCache::getArmyPic(Army *a, bool greyed)
602 return getArmyPic(a->getOwner()->getArmyset(), a->getTypeId(),
603 a->getOwner(), NULL, greyed);
606 PixMask* GraphicsCache::getArmyPic(guint32 armyset, guint32 army_id,
607 const Player* p, const bool *medals,
610 debug("getting army pic " <<armyset <<" " <<army <<" " <<p->getName() <<
613 std::list<ArmyCacheItem*>::iterator it;
614 ArmyCacheItem* myitem;
616 // important: medals can be 0 in special cases
617 bool my_medals[3] = {0,0,0};
619 for (int i = 0; i < 3; i++)
620 my_medals[i] = medals[i];
622 // special situation: ruin keepers don't belong to any player
623 // we don't actually show them, but what the heck
625 p = Playerlist::getInstance()->getNeutral();
627 ArmyCacheItem item = ArmyCacheItem();
628 item.armyset = armyset;
629 item.army_id = army_id;
630 item.player_id = p->getId();
631 item.medals[0] = my_medals[0];
632 item.medals[1] = my_medals[1];
633 item.medals[2] = my_medals[2];
634 item.greyed = greyed;
635 ArmyMap::iterator mit = d_armymap.find(item);
636 if (mit != d_armymap.end())
638 std::list<ArmyCacheItem*>::iterator it = (*mit).second;
640 d_armylist.erase(it);
641 d_armylist.push_back(myitem);
642 it = d_armylist.end();
644 d_armymap[*myitem] = it;
645 return myitem->surface;
648 // We are still here, so the graphic is not in the cache. addArmyPic calls
649 // checkPictures on its own, so we can simply return the surface
650 debug("getarmypic============= " << my_medals)
651 myitem = addArmyPic(&item);
653 return myitem->surface;
656 PixMask* GraphicsCache::getTilePic(int tile_style_id, int fog_type_id, bool has_bag, bool has_standard, int standard_player_id, int stack_size, int stack_player_id, int army_type_id, bool has_tower, bool has_ship, Maptile::Building building_type, int building_subtype, Vector<int> building_tile, int building_player_id, guint32 tilesize, bool has_grid)
658 guint32 tileset = GameMap::getInstance()->getTileset()->getId();
659 guint32 cityset = GameMap::getInstance()->getCityset()->getId();
660 return getTilePic(tile_style_id, fog_type_id, has_bag, has_standard, standard_player_id, stack_size, stack_player_id, army_type_id, has_tower, has_ship, building_type, building_subtype, building_tile, building_player_id, tilesize, has_grid, tileset, cityset);
663 PixMask* GraphicsCache::getTilePic(int tile_style_id, int fog_type_id, bool has_bag, bool has_standard, int standard_player_id, int stack_size, int stack_player_id, int army_type_id, bool has_tower, bool has_ship, Maptile::Building building_type, int building_subtype, Vector<int> building_tile, int building_player_id, guint32 tilesize, bool has_grid, guint32 tileset, guint32 cityset)
665 debug("getting tile pic " << tile_style_id << " " <<
666 fog_type_id << " " << has_bag << " " << has_standard << " " <<
667 standard_player_id << " " << stack_size << " " << stack_player_id <<
668 " " << army_type_id << " " << has_tower << " " << has_ship << " " <<
669 building_type << " " << building_subtype << " " << building_tile.x
670 << "," << building_tile.y << " " << building_player_id << " " <<
671 tilesize << " " << has_grid << " " <<tileset);
673 std::list<TileCacheItem*>::iterator it;
674 TileCacheItem* myitem;
676 TileCacheItem item = TileCacheItem();
677 item.tilesize = tilesize;
678 item.tile_style_id = tile_style_id;
679 item.has_bag = has_bag;
680 item.has_standard = has_standard;
681 item.standard_player_id = standard_player_id;
682 item.stack_size = stack_size;
683 item.stack_player_id = stack_player_id;
684 item.army_type_id = army_type_id;
685 item.has_tower = has_tower;
686 item.has_ship = has_ship;
687 item.building_type= building_type;
688 item.building_subtype= building_subtype;
689 item.building_tile = building_tile;
690 item.building_player_id = building_player_id;
691 item.has_grid = has_grid;
692 item.fog_type_id = fog_type_id;
693 item.tileset = tileset;
694 item.cityset = cityset;
695 TileMap::iterator mit = d_tilemap.find(item);
696 if (mit != d_tilemap.end())
698 std::list<TileCacheItem*>::iterator it = (*mit).second;
700 d_tilelist.erase(it);
701 d_tilelist.push_back(myitem);
702 it = d_tilelist.end();
704 d_tilemap[*myitem] = it;
705 return myitem->surface;
708 // We are still here, so the graphic is not in the cache. addTilePic calls
709 // checkPictures on its own, so we can simply return the surface
710 myitem = addTilePic(&item);
712 return myitem->surface;
715 PixMask* GraphicsCache::getShieldPic(guint32 shieldset, guint32 type,
718 debug("getting shield pic " <<shieldset <<" " <<type <<" " <<colour)
720 std::list<ShieldCacheItem*>::iterator it;
721 ShieldCacheItem* myitem;
723 for (it =d_shieldlist.begin(); it != d_shieldlist.end(); it++)
725 if ((*it)->shieldset == shieldset && (*it)->type == type
726 && (*it)->colour == colour)
730 // put the item on the last place (==last touched)
731 d_shieldlist.erase(it);
732 d_shieldlist.push_back(myitem);
734 return myitem->surface;
738 // We are still here, so the graphic is not in the cache. addShieldPic calls
739 // checkPictures on its own, so we can simply return the surface
740 myitem = addShieldPic(shieldset, type, colour);
742 return myitem->surface;
745 PixMask* GraphicsCache::getShieldPic(guint32 type, Player *p)
747 guint32 shieldset = GameMap::getInstance()->getShieldset()->getId();
748 return getShieldPic(shieldset, type, p->getId());
751 PixMask* GraphicsCache::getTemplePic(int type)
753 guint32 cityset = GameMap::getInstance()->getCityset()->getId();
754 return getTemplePic(type, cityset);
756 PixMask* GraphicsCache::getTemplePic(int type, guint32 cityset)
758 debug("GraphicsCache::getTemplePic " <<type)
760 std::list<TempleCacheItem*>::iterator it;
761 TempleCacheItem* myitem;
763 for (it = d_templelist.begin(); it != d_templelist.end(); it++)
765 if ((*it)->type == type && (*it)->cityset == cityset)
769 //put the item in last place (last touched)
770 d_templelist.erase(it);
771 d_templelist.push_back(myitem);
773 return myitem->surface;
777 //no item found -> create a new one
778 myitem = addTemplePic(type, cityset);
780 return myitem->surface;
783 PixMask* GraphicsCache::getRuinPic(int type)
785 guint32 cityset = GameMap::getInstance()->getCityset()->getId();
786 return getRuinPic(type, cityset);
788 PixMask* GraphicsCache::getRuinPic(int type, guint32 cityset)
790 debug("GraphicsCache::getRuinPic " <<type)
792 std::list<RuinCacheItem*>::iterator it;
793 RuinCacheItem* myitem;
795 for (it = d_ruinlist.begin(); it != d_ruinlist.end(); it++)
797 if ((*it)->type == type && (*it)->cityset == cityset)
801 //put the item in last place (last touched)
802 d_ruinlist.erase(it);
803 d_ruinlist.push_back(myitem);
805 return myitem->surface;
809 //no item found -> create a new one
810 myitem = addRuinPic(type, cityset);
812 return myitem->surface;
815 PixMask* GraphicsCache::getDiplomacyPic(int type, Player::DiplomaticState state)
817 debug("GraphicsCache::getDiplomaticPic " <<type << ", " << state)
819 std::list<DiplomacyCacheItem*>::iterator it;
820 DiplomacyCacheItem* myitem;
822 for (it = d_diplomacylist.begin(); it != d_diplomacylist.end(); it++)
824 if ((*it)->type == type && (*it)->state == state)
828 //put the item in last place (last touched)
829 d_diplomacylist.erase(it);
830 d_diplomacylist.push_back(myitem);
832 return myitem->surface;
836 //no item found -> create a new one
837 myitem = addDiplomacyPic(type, state);
839 return myitem->surface;
842 PixMask* GraphicsCache::getRoadPic(int type)
844 return getRoadPic(type, GameMap::getInstance()->getTileset()->getId());
846 PixMask* GraphicsCache::getRoadPic(int type, guint32 tileset)
848 debug("GraphicsCache::getRoadPic " <<type)
850 std::list<RoadCacheItem*>::iterator it;
851 RoadCacheItem* myitem;
853 for (it = d_roadlist.begin(); it != d_roadlist.end(); it++)
855 if ((*it)->type == type && (*it)->tileset == tileset)
859 //put the item in last place (last touched)
860 d_roadlist.erase(it);
861 d_roadlist.push_back(myitem);
863 return myitem->surface;
867 //no item found -> create a new one
868 myitem = addRoadPic(type, tileset);
870 return myitem->surface;
873 PixMask* GraphicsCache::getFogPic(int type)
875 return getFogPic(type, GameMap::getInstance()->getTileset()->getId());
878 PixMask* GraphicsCache::getFogPic(int type, guint32 tileset)
880 debug("GraphicsCache::getFogPic " <<type)
882 std::list<FogCacheItem*>::iterator it;
883 FogCacheItem* myitem;
885 FogCacheItem item = FogCacheItem();
887 item.tileset = tileset;
888 FogCacheMap::iterator mit = d_fogmap.find(item);
889 if (mit != d_fogmap.end())
891 std::list<FogCacheItem*>::iterator it = (*mit).second;
894 d_foglist.push_back(myitem);
895 it = d_foglist.end();
897 d_fogmap[*myitem] = it;
898 return myitem->surface;
901 //no item found -> create a new one
902 myitem = addFogPic(&item);
904 return myitem->surface;
907 PixMask* GraphicsCache::getBridgePic(int type)
909 return getBridgePic(type, GameMap::getInstance()->getTileset()->getId());
911 PixMask* GraphicsCache::getBridgePic(int type, guint32 tileset)
913 debug("GraphicsCache::getBridgePic " <<type)
915 std::list<BridgeCacheItem*>::iterator it;
916 BridgeCacheItem* myitem;
918 for (it = d_bridgelist.begin(); it != d_bridgelist.end(); it++)
920 if ((*it)->type == type && (*it)->tileset == tileset)
924 //put the item in last place (last touched)
925 d_bridgelist.erase(it);
926 d_bridgelist.push_back(myitem);
928 return myitem->surface;
932 //no item found -> create a new one
933 myitem = addBridgePic(type, tileset);
935 return myitem->surface;
938 PixMask* GraphicsCache::getCursorPic(int type)
940 debug("GraphicsCache::getCursorPic " <<type)
942 std::list<CursorCacheItem*>::iterator it;
943 CursorCacheItem* myitem;
945 for (it = d_cursorlist.begin(); it != d_cursorlist.end(); it++)
947 if ((*it)->type == type)
951 //put the item in last place (last touched)
952 d_cursorlist.erase(it);
953 d_cursorlist.push_back(myitem);
955 return myitem->surface;
959 //no item found -> create a new one
960 myitem = addCursorPic(type);
962 return myitem->surface;
965 PixMask* GraphicsCache::getCityPic(const City* city, guint32 cityset)
970 if (city->isBurnt() == true)
974 return getCityPic(type, city->getOwner(), cityset);
977 PixMask* GraphicsCache::getCityPic(const City* city)
979 guint32 cityset = GameMap::getInstance()->getCityset()->getId();
980 return getCityPic(city, cityset);
983 PixMask* GraphicsCache::getCityPic(int type, const Player* p, guint32 cityset)
985 debug("GraphicsCache::getCityPic " <<type)
987 std::list<CityCacheItem*>::iterator it;
988 CityCacheItem* myitem;
990 for (it = d_citylist.begin(); it != d_citylist.end(); it++)
992 if ((*it)->type == type && (*it)->cityset == cityset &&
993 (*it)->player_id == p->getId())
997 //put the item in last place (last touched)
998 d_citylist.erase(it);
999 d_citylist.push_back(myitem);
1001 return myitem->surface;
1005 //no item found -> create a new one
1006 myitem = addCityPic(type, p, cityset);
1008 return myitem->surface;
1011 PixMask* GraphicsCache::getTowerPic(const Player* p)
1013 guint32 cityset = GameMap::getInstance()->getCityset()->getId();
1014 return getTowerPic(p, cityset);
1017 PixMask* GraphicsCache::getTowerPic(const Player* p, guint32 cityset)
1019 debug("GraphicsCache::getTowerPic player " <<p->getName())
1021 std::list<TowerCacheItem*>::iterator it;
1022 TowerCacheItem* myitem;
1024 for (it = d_towerlist.begin(); it != d_towerlist.end(); it++)
1026 if ((*it)->cityset == cityset && (*it)->player_id == p->getId())
1030 //put the item in last place (last touched)
1031 d_towerlist.erase(it);
1032 d_towerlist.push_back(myitem);
1034 return myitem->surface;
1038 //no item found -> create a new one
1039 myitem = addTowerPic(p, cityset);
1041 return myitem->surface;
1044 PixMask* GraphicsCache::getFlagPic(guint32 stack_size, const Player *p, guint32 tileset)
1046 if (stack_size > MAX_STACK_SIZE || p == NULL || tileset == 0)
1048 debug("GraphicsCache::getFlagPic " <<stack_size <<", player" <<p->getId())
1050 std::list<FlagCacheItem*>::iterator it;
1051 FlagCacheItem* myitem;
1053 for (it = d_flaglist.begin(); it != d_flaglist.end(); it++)
1056 if (myitem->size == stack_size && myitem->player_id == p->getId() &&
1057 myitem->tileset == tileset)
1059 // put the item in last place (last touched)
1060 d_flaglist.erase(it);
1061 d_flaglist.push_back(myitem);
1063 return myitem->surface;
1067 // no item found => create a new one
1068 myitem = addFlagPic(stack_size, p, tileset);
1070 return myitem->surface;
1072 PixMask* GraphicsCache::getFlagPic(guint32 stack_size, const Player *p)
1074 return getFlagPic(stack_size, p,
1075 GameMap::getInstance()->getTileset()->getId());
1078 PixMask* GraphicsCache::getFlagPic(const Stack* s)
1080 return getFlagPic(s, GameMap::getInstance()->getTileset()->getId());
1082 PixMask* GraphicsCache::getFlagPic(const Stack* s, guint32 tileset)
1086 std::cerr << "GraphicsCache::getFlagPic: no stack supplied! Exiting...\n";
1090 return getFlagPic(s->size(), s->getOwner(), tileset);
1093 PixMask* GraphicsCache::getSelectorPic(guint32 type, guint32 frame,
1096 return getSelectorPic(type, frame, p,
1097 GameMap::getInstance()->getTileset()->getId());
1099 PixMask* GraphicsCache::getSelectorPic(guint32 type, guint32 frame,
1100 const Player *p, guint32 tileset)
1102 debug("GraphicsCache::getSelectorPic " <<type <<", " << frame << ", player" <<s->getOwner()->getName())
1106 std::cerr << "GraphicsCache::getSelectorPic: no player supplied! Exiting...\n";
1110 std::list<SelectorCacheItem*>::iterator it;
1111 SelectorCacheItem* myitem;
1113 for (it = d_selectorlist.begin(); it != d_selectorlist.end(); it++)
1116 if ((myitem->type == type) && (myitem->player_id == p->getId())
1117 && myitem->frame == frame && myitem->tileset == tileset)
1119 // put the item in last place (last touched)
1120 d_selectorlist.erase(it);
1121 d_selectorlist.push_back(myitem);
1123 return myitem->surface;
1127 // no item found => create a new one
1128 myitem = addSelectorPic(type, frame, p, tileset);
1130 return myitem->surface;
1134 PixMask* GraphicsCache::getProdShieldPic(guint32 type, bool prod)
1136 debug("GraphicsCache::getProdShieldPic " <<type <<", " << ", prod " <<prod)
1138 std::list<ProdShieldCacheItem*>::iterator it;
1139 ProdShieldCacheItem* myitem;
1141 for (it = d_prodshieldlist.begin(); it != d_prodshieldlist.end(); it++)
1144 if ((myitem->type == type) && (myitem->prod == prod))
1146 // put the item in last place (last touched)
1147 d_prodshieldlist.erase(it);
1148 d_prodshieldlist.push_back(myitem);
1150 return myitem->surface;
1154 // no item found => create a new one
1155 myitem = addProdShieldPic(type, prod);
1157 return myitem->surface;
1161 PixMask* GraphicsCache::applyMask(PixMask* image, PixMask* mask, Gdk::Color colour, bool isNeutral)
1163 int width = image->get_width();
1164 int height = image->get_height();
1165 PixMask* result = PixMask::create(image->to_pixbuf());
1166 if (mask->get_width() != width || (mask->get_height()) != height)
1168 std::cerr <<"Warning: mask and original image do not match\n";
1174 Glib::RefPtr<Gdk::Pixbuf> maskbuf = mask->to_pixbuf();
1176 guint8 *data = maskbuf->get_pixels();
1177 guint8 *copy = (guint8*) malloc (height * width * 4 * sizeof(guint8));
1178 memcpy(copy, data, height * width * 4 * sizeof(guint8));
1179 for (int i = 0; i < width; i++)
1180 for (int j = 0; j < height; j++)
1182 const int base = (j * 4) + (i * height * 4);
1184 if (copy[base+3] != 0)
1186 copy[base+0] = colour.get_red_p() *copy[base+0];
1187 copy[base+1] = colour.get_green_p() * copy[base+1];
1188 copy[base+2] = colour.get_blue_p() * copy[base+2];
1191 Glib::RefPtr<Gdk::Pixbuf> colouredmask =
1192 Gdk::Pixbuf::create_from_data(copy, Gdk::COLORSPACE_RGB, true, 8,
1193 width, height, width * 4);
1194 result->draw_pixbuf(colouredmask, 0, 0, 0, 0, width, height);
1200 PixMask* GraphicsCache::greyOut(PixMask* image)
1202 int width = image->get_width();
1203 int height = image->get_height();
1204 PixMask* result = PixMask::create(image->to_pixbuf());
1206 guint8 *data = result->to_pixbuf()->get_pixels();
1207 guint8 *copy = (guint8*) malloc (height * width * 4 * sizeof(guint8));
1208 memcpy(copy, data, height * width * 4 * sizeof(guint8));
1209 for (int i = 0; i < width; i++)
1210 for (int j = 0; j < height; j++)
1212 const int base = (j * 4) + (i * height * 4);
1214 if (data[base+3] != 0)
1217 if (copy[base+0] > max)
1219 else if (copy[base+1] > max)
1221 else if (copy[base+2] > max)
1225 if ((x == 0 && y == 0) || (x == 1 && y == 1))
1232 Glib::RefPtr<Gdk::Pixbuf> greyed_out =
1233 Gdk::Pixbuf::create_from_data(copy, Gdk::COLORSPACE_RGB, true, 8,
1234 width, height, width * 4);
1236 result->draw_pixbuf(greyed_out, 0, 0, 0, 0, width, height);
1242 PixMask* GraphicsCache::applyMask(PixMask* image, PixMask* mask, const Player* p)
1244 return applyMask(image, mask, p->getColor(),
1245 Playerlist::getInstance()->getNeutral()->getId() == p->getId());
1248 void GraphicsCache::checkPictures()
1250 // for security, we always take a minimum cache size of 2MB. This
1251 // includes (at 4 byte color depth and assuming 64x64 pixel size)
1252 // - 10 cities (each 64kb => 640kb)
1253 // - 20 flags (each 16kb => 320kb)
1254 // - 40 units (each 16kb => 640kb)
1255 // + a bit more. The problem is that if we have less images than needed
1256 // for a single rendering, the surfaces will become invalid before actually
1257 // used. This should not be a problem with the normal map (the surfaces are
1258 // copied and discarded), but when selecting armies from armyset, where
1259 // you can have these images assigned to buttons.
1260 guint32 maxcache = Configuration::s_cacheSize;
1261 if (maxcache < (1<<21))
1264 if (d_cachesize < maxcache)
1268 // Now the cache size has been exceeded. We try to guarantee the values
1269 // given above and reduce the number of images. Let us start with the
1272 while (d_citylist.size() > 10)
1273 eraseLastCityItem();
1275 while (d_towerlist.size() > 10)
1276 eraseLastTowerItem();
1278 while (d_shiplist.size() > 10)
1279 eraseLastShipItem();
1281 while (d_plantedstandardlist.size() > 10)
1282 eraseLastPlantedStandardItem();
1284 while (d_newlevellist.size() > 10)
1285 eraseLastNewLevelItem();
1287 while (d_templelist.size() > 10)
1288 eraseLastTempleItem();
1290 while (d_ruinlist.size() > 10)
1291 eraseLastRuinItem();
1293 while (d_diplomacylist.size() > 10)
1294 eraseLastDiplomacyItem();
1296 while (d_roadlist.size() > 18)
1297 eraseLastRoadItem();
1299 while (d_foglist.size() > 16)
1302 while (d_bridgelist.size() > 10)
1303 eraseLastBridgeItem();
1305 while (d_cursorlist.size() > 10)
1306 eraseLastCursorItem();
1309 if (d_cachesize < maxcache)
1312 // next, kill flag pics
1313 while (d_flaglist.size() > 20)
1314 eraseLastFlagItem();
1316 if (d_cachesize < maxcache)
1319 // next, kill selector pics
1320 while (d_selectorlist.size() > 20)
1321 eraseLastSelectorItem();
1323 if (d_cachesize < maxcache)
1326 // next, kill shield pics
1327 while (d_shieldlist.size() > 20)
1328 eraseLastShieldItem();
1330 if (d_cachesize < maxcache)
1333 // next, kill production shield pics
1334 while (d_prodshieldlist.size() > 20)
1335 eraseLastProdShieldItem();
1337 if (d_cachesize < maxcache)
1340 // next, kill port pics
1341 while (d_portlist.size() > 1)
1342 eraseLastPortItem();
1344 if (d_cachesize < maxcache)
1347 // next, kill signpost pics
1348 while (d_signpostlist.size() > 1)
1349 eraseLastSignpostItem();
1351 if (d_cachesize < maxcache)
1354 // next, kill bag pics
1355 while (d_baglist.size() > 1)
1358 if (d_cachesize < maxcache)
1361 // next, kill explosion pics
1362 while (d_explosionlist.size() > 1)
1363 eraseLastExplosionItem();
1365 if (d_cachesize < maxcache)
1368 // next, kill movement bonus pics
1369 while (d_movebonuslist.size() > 20)
1370 eraseLastMoveBonusItem();
1372 if (d_cachesize < maxcache)
1375 // still not enough? Erase tile images
1376 while (d_tilelist.size() > 200)
1377 eraseLastTileItem();
1379 // still not enough? Erase army images
1380 while (d_armylist.size() > 40)
1381 eraseLastArmyItem();
1385 void GraphicsCache::drawTilePic(PixMask *surface, int fog_type_id, bool has_bag, bool has_standard, int standard_player_id, int stack_size, int stack_player_id, int army_type_id, bool has_tower, bool has_ship, Maptile::Building building_type, int building_subtype, Vector<int> building_tile, int building_player_id, guint32 ts, bool has_grid, guint32 tileset, guint32 cityset)
1387 const Player *player;
1388 Glib::RefPtr<Gdk::Pixmap> pixmap = surface->get_pixmap();
1390 switch (building_type)
1394 player = Playerlist::getInstance()->getPlayer(building_player_id);
1395 getCityPic(building_subtype, player, cityset)->blit(building_tile, ts, pixmap);
1399 getRuinPic(building_subtype, cityset)->blit(building_tile, ts, pixmap); break;
1400 case Maptile::TEMPLE:
1401 getTemplePic(building_subtype, cityset)->blit(building_tile, ts, pixmap); break;
1402 case Maptile::SIGNPOST:
1403 getSignpostPic(cityset)->blit(building_tile, ts, pixmap); break;
1405 getRoadPic(building_subtype)->blit(building_tile, ts, pixmap); break;
1407 getPortPic(cityset)->blit(building_tile, ts, pixmap); break;
1408 case Maptile::BRIDGE:
1409 getBridgePic(building_subtype)->blit(building_tile, ts, pixmap); break;
1411 case Maptile::NONE: default:
1417 player = Playerlist::getInstance()->getPlayer(standard_player_id) ;
1418 getPlantedStandardPic(player)->blit(pixmap);
1423 PixMask *pic = getBagPic();
1424 Vector<int>bagsize = Vector<int>(pic->get_width(), pic->get_height());
1425 pic->blit(pixmap, Vector<int>(ts,ts)-bagsize);
1428 if (stack_player_id > -1)
1430 player = Playerlist::getInstance()->getPlayer(stack_player_id);
1432 getTowerPic(player)->blit(pixmap);
1435 if (stack_size > -1)
1436 getFlagPic(stack_size, player)->blit(pixmap);
1438 getShipPic(player)->blit(pixmap);
1440 getArmyPic(player->getArmyset(), army_type_id, player, NULL)->blit(pixmap);
1445 Glib::RefPtr<Gdk::GC> context = surface->get_gc();
1446 Gdk::Color line_color = Gdk::Color();
1447 line_color.set_rgb_p(0,0,0);
1448 context->set_rgb_fg_color(line_color);
1449 pixmap->draw_rectangle(context, false, 0, 0, ts, ts);
1455 Tilesetlist::getInstance()->getTileset(tileset);
1456 t->getFogImage(fog_type_id - 1)->blit(pixmap);
1460 TileCacheItem* GraphicsCache::addTilePic(TileCacheItem *item)
1463 debug("ADD tile pic " << " " << item->tile_style_id << " " <<
1464 item->fog_type_id << " " << item->has_bag << " " <<
1465 item->has_standard << " " << item->standard_player_id << " " <<
1466 item->stack_size << " " << item->stack_player_id <<
1467 " " << item->army_type_id << " " << item->has_tower << " " <<
1468 item->has_ship << " " << item->building_type << " " <<
1469 item->building_subtype << " " << item->building_tile.x <<
1470 "," << item->building_tile.y << " " << item->building_player_id <<
1471 " " << item->tilesize << " " << item->has_grid << " " << item->tileset
1472 " " << item->cityset);
1474 TileCacheItem* myitem = new TileCacheItem();
1477 //short circuit the drawing sequence if the tile is completely obscured
1478 Tileset *t = Tilesetlist::getInstance()->getTileset(item->tileset);
1479 if (myitem->fog_type_id == FogMap::ALL)
1480 myitem->surface = t->getFogImage(myitem->fog_type_id - 1)->copy();
1484 t->getTileStyle(myitem->tile_style_id)->getImage()->copy();
1486 drawTilePic(myitem->surface, myitem->fog_type_id, myitem->has_bag,
1487 myitem->has_standard, myitem->standard_player_id,
1488 myitem->stack_size, myitem->stack_player_id,
1489 myitem->army_type_id, myitem->has_tower, myitem->has_ship,
1490 myitem->building_type, myitem->building_subtype,
1491 myitem->building_tile, myitem->building_player_id,
1492 myitem->tilesize, myitem->has_grid, myitem->tileset,
1496 //now the final preparation steps:
1498 int size = myitem->surface->get_width() * myitem->surface->get_height();
1499 d_cachesize += myitem->surface->get_depth()/8 * size;
1501 //b) add the entry to the list
1502 d_tilelist.push_back(myitem);
1503 std::list<TileCacheItem*>::iterator it = d_tilelist.end();
1505 d_tilemap[*myitem] = it;
1507 //c) check if the cache size is too large
1510 //we are finished, so return the pic
1514 ArmyCacheItem* GraphicsCache::addArmyPic(ArmyCacheItem *item)
1516 debug("ADD army pic: " <<item->armyset <<"," <<item->army_id)
1518 ArmyCacheItem* myitem = new ArmyCacheItem();
1521 const ArmyProto * basearmy =
1522 Armysetlist::getInstance()->getArmy(myitem->armyset, myitem->army_id);
1524 // copy the pixmap including player colors
1525 Player *p = Playerlist::getInstance()->getPlayer(myitem->player_id);
1526 Shield::Colour c = Shield::Colour(p->getId());
1527 PixMask *coloured = applyMask(basearmy->getImage(c), basearmy->getMask(c), p);
1530 PixMask *greyed_out = greyOut(coloured);
1531 myitem->surface = greyed_out;
1535 myitem->surface = coloured;
1537 if (myitem->medals != NULL)
1539 debug("medalsbonus============= " << medalsbonus);
1540 for(int i=0;i<3;i++)
1542 if (myitem->medals[i])
1543 d_medalpic[0][i]->blit(myitem->surface->get_pixmap());
1547 //now the final preparation steps:
1549 int size = myitem->surface->get_width() * myitem->surface->get_height();
1550 d_cachesize += myitem->surface->get_depth()/8 * size;
1552 //b) add the entry to the list
1553 d_armylist.push_back(myitem);
1554 std::list<ArmyCacheItem*>::iterator it = d_armylist.end();
1556 d_armymap[*myitem] = it;
1558 //c) check if the cache size is too large
1561 //we are finished, so return the pic
1565 ShieldCacheItem* GraphicsCache::addShieldPic(guint32 shieldset, guint32 type,
1568 debug("ADD shield pic: " <<shieldset <<"," <<type <<"," <<colour)
1570 ShieldCacheItem* myitem = new ShieldCacheItem();
1571 myitem->shieldset = shieldset;
1572 myitem->type = type;
1573 myitem->colour = colour;
1576 sh = Shieldsetlist::getInstance()->getShield(shieldset, type, colour);
1578 // copy the pixmap including player colors
1579 //lookup the shieldstyle
1580 myitem->surface = applyMask(sh->getImage(), sh->getMask(),
1581 Playerlist::getInstance()->getPlayer(colour));
1583 //now the final preparation steps:
1585 int size = myitem->surface->get_width() * myitem->surface->get_height();
1586 d_cachesize += myitem->surface->get_depth()/8 * size;
1588 //b) add the entry to the list
1589 d_shieldlist.push_back(myitem);
1591 //c) check if the cache size is too large
1594 //we are finished, so return the pic
1599 ShipCacheItem* GraphicsCache::addShipPic(const Player* p)
1601 debug("ADD ship pic: " <<p->getName())
1603 ShipCacheItem* myitem = new ShipCacheItem();
1604 myitem->player_id = p->getId();
1605 myitem->armyset = p->getArmyset();
1607 Armysetlist *al = Armysetlist::getInstance();
1608 PixMask*ship = al->getShipPic(p->getArmyset());
1609 PixMask*shipmask = al->getShipMask(p->getArmyset());
1610 // copy the pixmap including player colors
1611 myitem->surface = applyMask(ship, shipmask, p);
1613 //now the final preparation steps:
1615 int size = myitem->surface->get_width() * myitem->surface->get_height();
1616 d_cachesize += myitem->surface->get_depth()/8 * size;
1618 //b) add the entry to the list
1619 d_shiplist.push_back(myitem);
1621 //c) check if the cache size is too large
1624 //we are finished, so return the pic
1628 NewLevelCacheItem* GraphicsCache::addNewLevelPic(const Player* p, guint32 gender)
1630 debug("ADD new level pic: " <<p->getName())
1632 NewLevelCacheItem* myitem = new NewLevelCacheItem();
1633 myitem->player_id = p->getId();
1634 myitem->gender = gender;
1636 // copy the pixmap including player colors
1637 if (gender == Hero::FEMALE)
1638 myitem->surface = applyMask(d_newlevel_female, d_newlevelmask_female, p);
1640 myitem->surface = applyMask(d_newlevel_male, d_newlevelmask_male, p);
1642 //now the final preparation steps:
1644 int size = myitem->surface->get_width() * myitem->surface->get_height();
1645 d_cachesize += myitem->surface->get_depth()/8 * size;
1647 //b) add the entry to the list
1648 d_newlevellist.push_back(myitem);
1650 //c) check if the cache size is too large
1653 //we are finished, so return the pic
1657 PortCacheItem* GraphicsCache::addPortPic(guint32 cityset)
1659 debug("ADD port pic: " << cityset);
1661 PortCacheItem* myitem = new PortCacheItem();
1662 myitem->cityset = cityset;
1664 Citysetlist *csl = Citysetlist::getInstance();
1665 Cityset *cs = csl->getCityset(cityset);
1668 myitem->surface = cs->getPortImage()->copy();
1670 //now the final preparation steps:
1672 int size = myitem->surface->get_width() * myitem->surface->get_height();
1673 d_cachesize += myitem->surface->get_depth()/8 * size;
1675 //b) add the entry to the list
1676 d_portlist.push_back(myitem);
1678 //c) check if the cache size is too large
1681 //we are finished, so return the pic
1685 ExplosionCacheItem* GraphicsCache::addExplosionPic(guint32 tileset)
1687 debug("ADD explosion pic: " << tileset);
1689 ExplosionCacheItem* myitem = new ExplosionCacheItem();
1690 myitem->tileset = tileset;
1694 Tilesetlist::getInstance()->getTileset(tileset)->getExplosionImage()->copy();
1696 //now the final preparation steps:
1698 int size = myitem->surface->get_width() * myitem->surface->get_height();
1699 d_cachesize += myitem->surface->get_depth()/8 * size;
1701 //b) add the entry to the list
1702 d_explosionlist.push_back(myitem);
1704 //c) check if the cache size is too large
1707 //we are finished, so return the pic
1711 BagCacheItem* GraphicsCache::addBagPic(guint32 armyset)
1713 debug("ADD bad pic: " << armyset);
1715 BagCacheItem* myitem = new BagCacheItem();
1716 myitem->armyset = armyset;
1719 myitem->surface = Armysetlist::getInstance()->getBagPic(armyset)->copy();
1721 //now the final preparation steps:
1723 int size = myitem->surface->get_width() * myitem->surface->get_height();
1724 d_cachesize += myitem->surface->get_depth()/8 * size;
1726 //b) add the entry to the list
1727 d_baglist.push_back(myitem);
1729 //c) check if the cache size is too large
1732 //we are finished, so return the pic
1736 SignpostCacheItem* GraphicsCache::addSignpostPic(guint32 cityset)
1738 debug("ADD signpost pic: " << cityset);
1740 SignpostCacheItem* myitem = new SignpostCacheItem();
1741 myitem->cityset = cityset;
1743 Citysetlist *csl = Citysetlist::getInstance();
1744 Cityset *cs = csl->getCityset(cityset);
1747 myitem->surface = cs->getSignpostImage()->copy();
1749 //now the final preparation steps:
1751 int size = myitem->surface->get_width() * myitem->surface->get_height();
1752 d_cachesize += myitem->surface->get_depth()/8 * size;
1754 //b) add the entry to the list
1755 d_signpostlist.push_back(myitem);
1757 //c) check if the cache size is too large
1760 //we are finished, so return the pic
1764 PlantedStandardCacheItem* GraphicsCache::addPlantedStandardPic(const Player* p)
1766 debug("ADD planted standard pic: " <<p->getName())
1768 PlantedStandardCacheItem* myitem = new PlantedStandardCacheItem();
1769 myitem->player_id = p->getId();
1770 myitem->armyset = p->getArmyset();
1772 Armysetlist *al = Armysetlist::getInstance();
1773 PixMask*standard = al->getStandardPic(p->getArmyset());
1774 PixMask*standard_mask = al->getStandardMask(p->getArmyset());
1776 // copy the pixmap including player colors
1777 myitem->surface = applyMask(standard, standard_mask, p);
1779 //now the final preparation steps:
1781 int size = myitem->surface->get_width() * myitem->surface->get_height();
1782 d_cachesize += myitem->surface->get_depth()/8 * size;
1784 //b) add the entry to the list
1785 d_plantedstandardlist.push_back(myitem);
1787 //c) check if the cache size is too large
1790 //we are finished, so return the pic
1795 TempleCacheItem* GraphicsCache::addTemplePic(int type, guint32 cityset)
1797 Cityset *cs = Citysetlist::getInstance()->getCityset(cityset);
1798 PixMask* mysurf = cs->getTempleImage(type)->copy();
1800 //now create the cache item and add the size
1801 TempleCacheItem* myitem = new TempleCacheItem();
1802 myitem->type = type;
1803 myitem->cityset = cityset;
1804 myitem->surface = mysurf;
1806 d_templelist.push_back(myitem);
1809 int size = mysurf->get_width() * mysurf->get_height();
1810 d_cachesize += size * mysurf->get_depth()/8;
1812 //and check the size of the cache
1818 RuinCacheItem* GraphicsCache::addRuinPic(int type, guint32 cityset)
1820 Cityset *cs = Citysetlist::getInstance()->getCityset(cityset);
1821 PixMask* mysurf = cs->getRuinImage(type)->copy();
1823 //now create the cache item and add the size
1824 RuinCacheItem* myitem = new RuinCacheItem();
1825 myitem->type = type;
1826 myitem->cityset = cityset;
1827 myitem->surface = mysurf;
1828 myitem->cityset = cityset;
1830 d_ruinlist.push_back(myitem);
1833 int size = mysurf->get_width() * mysurf->get_height();
1834 d_cachesize += size * mysurf->get_depth()/8;
1836 //and check the size of the cache
1842 DiplomacyCacheItem* GraphicsCache::addDiplomacyPic(int type, Player::DiplomaticState state)
1845 d_diplomacypic[type][state - Player::AT_PEACE];
1847 //now create the cache item and add the size
1848 DiplomacyCacheItem* myitem = new DiplomacyCacheItem();
1849 myitem->type = type;
1850 myitem->state = state;
1851 myitem->surface = mysurf;
1853 d_diplomacylist.push_back(myitem);
1856 int size = mysurf->get_width() * mysurf->get_height();
1857 d_cachesize += size * mysurf->get_depth()/8;
1859 //and check the size of the cache
1865 RoadCacheItem* GraphicsCache::addRoadPic(int type, guint32 tileset)
1867 Tileset *ts = Tilesetlist::getInstance()->getTileset(tileset);
1868 PixMask* mysurf = ts->getRoadImage(type)->copy();
1870 //now create the cache item and add the size
1871 RoadCacheItem* myitem = new RoadCacheItem();
1872 myitem->type = type;
1873 myitem->tileset = tileset;
1874 myitem->surface = mysurf;
1876 d_roadlist.push_back(myitem);
1879 int size = mysurf->get_width() * mysurf->get_height();
1880 d_cachesize += size * mysurf->get_depth()/8;
1882 //and check the size of the cache
1888 FogCacheItem* GraphicsCache::addFogPic(FogCacheItem *item)
1890 Tileset *ts = Tilesetlist::getInstance()->getTileset(item->tileset);
1891 PixMask* mysurf = ts->getFogImage(item->type - 1)->copy();
1893 //now create the cache item and add the size
1894 FogCacheItem* myitem = new FogCacheItem();
1896 myitem->surface = mysurf;
1898 d_foglist.push_back(myitem);
1899 std::list<FogCacheItem*>::iterator it = d_foglist.end();
1901 d_fogmap[*myitem] = it;
1904 int size = mysurf->get_width() * mysurf->get_height();
1905 d_cachesize += size * mysurf->get_depth()/8;
1907 //and check the size of the cache
1913 BridgeCacheItem* GraphicsCache::addBridgePic(int type, guint32 tileset)
1915 Tileset *ts = Tilesetlist::getInstance()->getTileset(tileset);
1916 PixMask* mysurf = ts->getBridgeImage(type)->copy();
1918 //now create the cache item and add the size
1919 BridgeCacheItem* myitem = new BridgeCacheItem();
1920 myitem->type = type;
1921 myitem->tileset = tileset;
1922 myitem->surface = mysurf;
1924 d_bridgelist.push_back(myitem);
1927 int size = mysurf->get_width() * mysurf->get_height();
1928 d_cachesize += size * mysurf->get_depth()/8;
1930 //and check the size of the cache
1936 CursorCacheItem* GraphicsCache::addCursorPic(int type)
1938 PixMask* mysurf = d_cursorpic[type];
1940 //now create the cache item and add the size
1941 CursorCacheItem* myitem = new CursorCacheItem();
1942 myitem->type = type;
1943 myitem->surface = mysurf;
1945 d_cursorlist.push_back(myitem);
1948 int size = mysurf->get_width() * mysurf->get_height();
1949 d_cachesize += size * mysurf->get_depth()/8;
1951 //and check the size of the cache
1957 CityCacheItem* GraphicsCache::addCityPic(int type, const Player* p, guint32 cityset)
1959 //now create the cache item and add the size
1960 CityCacheItem* myitem = new CityCacheItem();
1961 myitem->cityset = cityset;
1962 myitem->player_id = p->getId();
1963 myitem->type = type;
1964 Cityset *cs = Citysetlist::getInstance()->getCityset(cityset);
1966 myitem->surface = cs->getRazedCityImage(p->getId())->copy();
1968 myitem->surface = cs->getCityImage(p->getId())->copy();
1970 d_citylist.push_back(myitem);
1973 int size = myitem->surface->get_width() * myitem->surface->get_height();
1974 d_cachesize += size * myitem->surface->get_depth()/8;
1976 //and check the size of the cache
1982 TowerCacheItem* GraphicsCache::addTowerPic(const Player* p, guint32 cityset)
1984 //now create the cache item and add the size
1985 TowerCacheItem* myitem = new TowerCacheItem();
1986 myitem->player_id = p->getId();
1987 myitem->cityset = cityset;
1988 Cityset *cs = Citysetlist::getInstance()->getCityset(cityset);
1989 myitem->surface = cs->getTowerImage(p->getId());
1991 d_towerlist.push_back(myitem);
1994 int size = myitem->surface->get_width() * myitem->surface->get_height();
1995 d_cachesize += size * myitem->surface->get_depth()/8;
1997 //and check the size of the cache
2003 FlagCacheItem* GraphicsCache::addFlagPic(int size, const Player *p, guint32 tileset)
2005 Tileset *ts = Tilesetlist::getInstance()->getTileset(tileset);
2006 debug("GraphicsCache::addFlagPic, player="<<p->getId()<<", size="<<size)
2008 // size of the stack starts at 1, but we need the index, which starts at 0
2010 PixMask* mysurf = applyMask (ts->getFlagImage(size-1),
2011 ts->getFlagMask(size-1), p);
2013 //now create the cache item and add the size
2014 FlagCacheItem* myitem = new FlagCacheItem();
2015 myitem->player_id = p->getId();
2016 myitem->size = size;
2017 myitem->tileset = tileset;
2018 myitem->surface = mysurf;
2020 d_flaglist.push_back(myitem);
2023 int picsize = mysurf->get_width() * mysurf->get_height();
2024 d_cachesize += picsize * mysurf->get_depth()/8;
2026 //and check the size of the cache
2032 SelectorCacheItem* GraphicsCache::addSelectorPic(guint32 type, guint32 frame, const Player* p, guint32 tileset)
2034 Tileset *ts = Tilesetlist::getInstance()->getTileset(tileset);
2035 debug("GraphicsCache::addSelectorPic, player="<<p->getName()<<", type="<<type<< ", " << frame)
2037 // frame is the frame of animation we're looking for. starts at 0.
2038 // type is 0 for big, 1 for small
2042 mysurf = applyMask(ts->getSelectorImage(frame), ts->getSelectorMask(frame), p);
2044 mysurf = applyMask(ts->getSmallSelectorImage(frame),
2045 ts->getSmallSelectorMask(frame), p);
2047 //now create the cache item and add the size
2048 SelectorCacheItem* myitem = new SelectorCacheItem();
2049 myitem->player_id = p->getId();
2050 myitem->type = type;
2051 myitem->tileset = tileset;
2052 myitem->frame = frame;
2053 myitem->surface = mysurf;
2055 d_selectorlist.push_back(myitem);
2058 int picsize = mysurf->get_width() * mysurf->get_height();
2059 d_cachesize += picsize * mysurf->get_depth()/8;
2061 //and check the size of the cache
2067 ProdShieldCacheItem* GraphicsCache::addProdShieldPic(guint32 type, bool prod)
2069 debug("GraphicsCache::addProdShieldPic, prod="<<prod<<", type="<<type)
2071 // type is 0 for home, 1 for away, 2 for destination, 3 for source,
2074 PixMask* mysurf = NULL;
2078 if (prod) //production
2079 mysurf = d_prodshieldpic[1]->copy();
2080 else //no production
2081 mysurf = d_prodshieldpic[0]->copy();
2084 if (prod) //production
2085 mysurf = d_prodshieldpic[3]->copy();
2086 else //no production
2087 mysurf = d_prodshieldpic[2]->copy();
2089 case 2: //destination city
2090 if (prod) //production
2091 mysurf = d_prodshieldpic[5]->copy();
2092 else //no production
2093 mysurf = d_prodshieldpic[4]->copy();
2095 case 3: //source city
2096 mysurf = d_prodshieldpic[6]->copy();
2099 mysurf = d_prodshieldpic[7]->copy();
2103 //now create the cache item and add the size
2104 ProdShieldCacheItem* myitem = new ProdShieldCacheItem();
2105 myitem->prod = prod;
2106 myitem->type = type;
2107 myitem->surface = mysurf;
2109 d_prodshieldlist.push_back(myitem);
2112 int picsize = mysurf->get_width() * mysurf->get_height();
2113 d_cachesize += picsize * mysurf->get_depth()/8;
2115 //and check the size of the cache
2121 MoveBonusCacheItem* GraphicsCache::addMoveBonusPic(guint32 type)
2123 debug("GraphicsCache::addMoveBonusPic, type="<<type)
2125 //type is 0=empty, 1=trees, 2=foothills, 3=hills+trees, 4=fly, 5=boat
2128 mysurf = d_movebonuspic[type]->copy();
2130 //now create the cache item and add the size
2131 MoveBonusCacheItem* myitem = new MoveBonusCacheItem();
2132 myitem->type = type;
2133 myitem->surface = mysurf;
2135 d_movebonuslist.push_back(myitem);
2138 int picsize = mysurf->get_width() * mysurf->get_height();
2139 d_cachesize += picsize * mysurf->get_depth()/8;
2141 //and check the size of the cache
2148 void GraphicsCache::clear()
2150 while (!d_armylist.empty())
2151 eraseLastArmyItem();
2153 while (!d_tilelist.empty())
2154 eraseLastTileItem();
2156 while (!d_templelist.empty())
2157 eraseLastTempleItem();
2159 while (!d_ruinlist.empty())
2160 eraseLastRuinItem();
2162 while (!d_diplomacylist.empty())
2163 eraseLastDiplomacyItem();
2165 while (!d_roadlist.empty())
2166 eraseLastRoadItem();
2168 while (!d_foglist.empty())
2171 while (!d_bridgelist.empty())
2172 eraseLastBridgeItem();
2174 while (!d_cursorlist.empty())
2175 eraseLastCursorItem();
2177 while (!d_citylist.empty())
2178 eraseLastCityItem();
2180 while (!d_towerlist.empty())
2181 eraseLastTowerItem();
2183 while (!d_shiplist.empty())
2184 eraseLastShipItem();
2186 while (!d_plantedstandardlist.empty())
2187 eraseLastPlantedStandardItem();
2189 while (!d_portlist.empty())
2190 eraseLastPortItem();
2192 while (!d_signpostlist.empty())
2193 eraseLastSignpostItem();
2195 while (!d_baglist.empty())
2198 while (!d_explosionlist.empty())
2199 eraseLastExplosionItem();
2201 while (!d_flaglist.empty())
2202 eraseLastFlagItem();
2204 while (!d_selectorlist.empty())
2205 eraseLastSelectorItem();
2207 while (!d_shieldlist.empty())
2208 eraseLastShieldItem();
2210 while (!d_prodshieldlist.empty())
2211 eraseLastProdShieldItem();
2213 while (!d_movebonuslist.empty())
2214 eraseLastMoveBonusItem();
2217 void GraphicsCache::eraseLastArmyItem()
2219 if (d_armylist.empty())
2222 //As the name suggests, this function erases the last item in the list.
2223 //Whenever an item is requested, it moves to the first position, so the
2224 //last item is the oldest and therefore propably most useless in the list.
2225 ArmyCacheItem* myitem = *(d_armylist.begin());
2226 ArmyMap::iterator it = d_armymap.find(*myitem);
2227 if (it != d_armymap.end())
2228 d_armymap.erase(it);
2229 d_armylist.erase(d_armylist.begin());
2231 //don't forget to subtract the size from the size entry
2232 int size = myitem->surface->get_width() * myitem->surface->get_height();
2233 d_cachesize -= myitem->surface->get_depth()/8 * size;
2235 delete myitem->surface;
2239 void GraphicsCache::eraseLastTileItem()
2241 if (d_tilelist.empty())
2244 //As the name suggests, this function erases the last item in the list.
2245 //Whenever an item is requested, it moves to the first position, so the
2246 //last item is the oldest and therefore propably most useless in the list.
2247 TileCacheItem* myitem = *(d_tilelist.begin());
2248 TileMap::iterator it = d_tilemap.find(*myitem);
2249 if (it != d_tilemap.end()) //fixme, find out why this check is necessary.
2250 d_tilemap.erase(it);
2251 d_tilelist.erase(d_tilelist.begin());
2253 //don't forget to subtract the size from the size entry
2254 int size = myitem->surface->get_width() * myitem->surface->get_height();
2255 d_cachesize -= myitem->surface->get_depth()/8 * size;
2257 delete myitem->surface;
2261 void GraphicsCache::eraseLastTempleItem()
2263 if (d_templelist.empty())
2266 TempleCacheItem* myitem = *(d_templelist.begin());
2267 d_templelist.erase(d_templelist.begin());
2269 int size = myitem->surface->get_width() * myitem->surface->get_height();
2270 d_cachesize -= myitem->surface->get_depth()/8 * size;
2272 delete myitem->surface;
2276 void GraphicsCache::eraseLastRuinItem()
2278 if (d_ruinlist.empty())
2281 RuinCacheItem* myitem = *(d_ruinlist.begin());
2282 d_ruinlist.erase(d_ruinlist.begin());
2284 int size = myitem->surface->get_width() * myitem->surface->get_height();
2285 d_cachesize -= myitem->surface->get_depth()/8 * size;
2287 delete myitem->surface;
2291 void GraphicsCache::eraseLastDiplomacyItem()
2293 if (d_diplomacylist.empty())
2296 DiplomacyCacheItem* myitem = *(d_diplomacylist.begin());
2297 d_diplomacylist.erase(d_diplomacylist.begin());
2299 int size = myitem->surface->get_width() * myitem->surface->get_height();
2300 d_cachesize -= myitem->surface->get_depth()/8 * size;
2302 delete myitem->surface;
2306 void GraphicsCache::eraseLastRoadItem()
2308 if (d_roadlist.empty())
2311 RoadCacheItem* myitem = *(d_roadlist.begin());
2312 d_roadlist.erase(d_roadlist.begin());
2314 int size = myitem->surface->get_width() * myitem->surface->get_height();
2315 d_cachesize -= myitem->surface->get_depth()/8 * size;
2317 delete myitem->surface;
2321 void GraphicsCache::eraseLastFogItem()
2323 if (d_foglist.empty())
2326 FogCacheItem* myitem = *(d_foglist.begin());
2327 FogCacheMap::iterator it = d_fogmap.find(*myitem);
2328 if (it != d_fogmap.end())
2330 d_foglist.erase(d_foglist.begin());
2332 int size = myitem->surface->get_width() * myitem->surface->get_height();
2333 d_cachesize -= myitem->surface->get_depth()/8 * size;
2335 delete myitem->surface;
2339 void GraphicsCache::eraseLastBridgeItem()
2341 if (d_bridgelist.empty())
2344 BridgeCacheItem* myitem = *(d_bridgelist.begin());
2345 d_bridgelist.erase(d_bridgelist.begin());
2347 int size = myitem->surface->get_width() * myitem->surface->get_height();
2348 d_cachesize -= myitem->surface->get_depth()/8 * size;
2350 delete myitem->surface;
2354 void GraphicsCache::eraseLastCursorItem()
2356 if (d_cursorlist.empty())
2359 CursorCacheItem* myitem = *(d_cursorlist.begin());
2360 d_cursorlist.erase(d_cursorlist.begin());
2362 int size = myitem->surface->get_width() * myitem->surface->get_height();
2363 d_cachesize -= myitem->surface->get_depth()/8 * size;
2365 delete myitem->surface;
2369 void GraphicsCache::eraseLastCityItem()
2371 if (d_citylist.empty())
2374 CityCacheItem* myitem = *(d_citylist.begin());
2375 d_citylist.erase(d_citylist.begin());
2377 int size = myitem->surface->get_width() * myitem->surface->get_height();
2378 d_cachesize -= myitem->surface->get_depth()/8 * size;
2380 delete myitem->surface;
2384 void GraphicsCache::eraseLastTowerItem()
2386 if (d_towerlist.empty())
2389 TowerCacheItem* myitem = *(d_towerlist.begin());
2390 d_towerlist.erase(d_towerlist.begin());
2392 int size = myitem->surface->get_width() * myitem->surface->get_height();
2393 d_cachesize -= myitem->surface->get_depth()/8 * size;
2395 delete myitem->surface;
2399 void GraphicsCache::eraseLastShipItem()
2401 if (d_shiplist.empty())
2404 ShipCacheItem* myitem = *(d_shiplist.begin());
2405 d_shiplist.erase(d_shiplist.begin());
2407 int size = myitem->surface->get_width() * myitem->surface->get_height();
2408 d_cachesize -= myitem->surface->get_depth()/8 * size;
2410 delete myitem->surface;
2414 void GraphicsCache::eraseLastNewLevelItem()
2416 if (d_newlevellist.empty())
2419 NewLevelCacheItem* myitem = *(d_newlevellist.begin());
2420 d_newlevellist.erase(d_newlevellist.begin());
2422 int size = myitem->surface->get_width() * myitem->surface->get_height();
2423 d_cachesize -= myitem->surface->get_depth()/8 * size;
2425 delete myitem->surface;
2429 void GraphicsCache::eraseLastExplosionItem()
2431 if (d_explosionlist.empty())
2434 ExplosionCacheItem* myitem = *(d_explosionlist.begin());
2435 d_explosionlist.erase(d_explosionlist.begin());
2437 int size = myitem->surface->get_width() * myitem->surface->get_height();
2438 d_cachesize -= myitem->surface->get_depth()/8 * size;
2440 delete myitem->surface;
2444 void GraphicsCache::eraseLastBagItem()
2446 if (d_baglist.empty())
2449 BagCacheItem* myitem = *(d_baglist.begin());
2450 d_baglist.erase(d_baglist.begin());
2452 int size = myitem->surface->get_width() * myitem->surface->get_height();
2453 d_cachesize -= myitem->surface->get_depth()/8 * size;
2455 delete myitem->surface;
2459 void GraphicsCache::eraseLastSignpostItem()
2461 if (d_signpostlist.empty())
2464 SignpostCacheItem* myitem = *(d_signpostlist.begin());
2465 d_signpostlist.erase(d_signpostlist.begin());
2467 int size = myitem->surface->get_width() * myitem->surface->get_height();
2468 d_cachesize -= myitem->surface->get_depth()/8 * size;
2470 delete myitem->surface;
2474 void GraphicsCache::eraseLastPortItem()
2476 if (d_portlist.empty())
2479 PortCacheItem* myitem = *(d_portlist.begin());
2480 d_portlist.erase(d_portlist.begin());
2482 int size = myitem->surface->get_width() * myitem->surface->get_height();
2483 d_cachesize -= myitem->surface->get_depth()/8 * size;
2485 delete myitem->surface;
2489 void GraphicsCache::eraseLastPlantedStandardItem()
2491 if (d_plantedstandardlist.empty())
2494 PlantedStandardCacheItem* myitem = *(d_plantedstandardlist.begin());
2495 d_plantedstandardlist.erase(d_plantedstandardlist.begin());
2497 int size = myitem->surface->get_width() * myitem->surface->get_height();
2498 d_cachesize -= myitem->surface->get_depth()/8 * size;
2500 delete myitem->surface;
2504 void GraphicsCache::eraseLastFlagItem()
2506 if (d_flaglist.empty())
2509 FlagCacheItem* myitem = *(d_flaglist.begin());
2510 d_flaglist.erase(d_flaglist.begin());
2512 int size = myitem->surface->get_width() * myitem->surface->get_height();
2513 d_cachesize -= myitem->surface->get_depth()/8 * size;
2515 delete myitem->surface;
2519 void GraphicsCache::eraseLastSelectorItem()
2521 if (d_selectorlist.empty())
2524 SelectorCacheItem* myitem = *(d_selectorlist.begin());
2525 d_selectorlist.erase(d_selectorlist.begin());
2527 int size = myitem->surface->get_width() * myitem->surface->get_height();
2528 d_cachesize -= myitem->surface->get_depth()/8 * size;
2530 delete myitem->surface;
2534 void GraphicsCache::eraseLastShieldItem()
2536 if (d_shieldlist.empty())
2539 ShieldCacheItem* myitem = *(d_shieldlist.begin());
2540 d_shieldlist.erase(d_shieldlist.begin());
2542 int size = myitem->surface->get_width() * myitem->surface->get_height();
2543 d_cachesize -= myitem->surface->get_depth()/8 * size;
2545 delete myitem->surface;
2549 void GraphicsCache::eraseLastProdShieldItem()
2551 if (d_prodshieldlist.empty())
2554 ProdShieldCacheItem* myitem = *(d_prodshieldlist.begin());
2555 d_prodshieldlist.erase(d_prodshieldlist.begin());
2557 int size = myitem->surface->get_width() * myitem->surface->get_height();
2558 d_cachesize -= myitem->surface->get_depth()/8 * size;
2560 delete myitem->surface;
2564 void GraphicsCache::eraseLastMoveBonusItem()
2566 if (d_movebonuslist.empty())
2569 MoveBonusCacheItem* myitem = *(d_movebonuslist.begin());
2570 d_movebonuslist.erase(d_movebonuslist.begin());
2572 int size = myitem->surface->get_width() * myitem->surface->get_height();
2573 d_cachesize -= myitem->surface->get_depth()/8 * size;
2575 delete myitem->surface;
2579 void GraphicsCache::loadDiplomacyPics()
2582 std::vector<PixMask* > diplomacypics;
2583 diplomacypics = disassemble_row(File::getMiscFile("various/diplomacy-small.png"),
2585 for (unsigned int i = 0; i < DIPLOMACY_TYPES ; i++)
2587 if (diplomacypics[i]->get_width() != ts)
2588 PixMask::scale(diplomacypics[i], ts, ts);
2589 d_diplomacypic[0][i] = diplomacypics[i];
2594 diplomacypics = disassemble_row(File::getMiscFile("various/diplomacy-large.png"),
2596 for (unsigned int i = 0; i < DIPLOMACY_TYPES ; i++)
2598 if (diplomacypics[i]->get_width() != ts)
2599 PixMask::scale(diplomacypics[i], ts, ts);
2600 d_diplomacypic[1][i] = diplomacypics[i];
2605 void GraphicsCache::loadCursorPics()
2609 // load the cursor pictures
2610 std::vector<PixMask* > cursorpics;
2611 cursorpics = disassemble_row(File::getMiscFile("various/cursors.png"),
2613 for (unsigned int i = 0; i < CURSOR_TYPES ; i++)
2615 if (cursorpics[i]->get_width() != ts)
2616 PixMask::scale(cursorpics[i], ts, ts);
2617 d_cursorpic[i] = cursorpics[i];
2621 bool GraphicsCache::loadSelectorImages(std::string filename, guint32 size, std::vector<PixMask* > &images, std::vector<PixMask* > &masks)
2624 num_frames = Gdk::Pixbuf::create_from_file (filename)->get_width() / size;
2625 images = disassemble_row(filename, num_frames, true);
2626 for (int i = 0; i < num_frames; i++)
2628 if (images[i]->get_width() != (int)size)
2629 PixMask::scale(images[i], size, size);
2632 masks = disassemble_row(filename, num_frames, false);
2633 for (int i = 0; i < num_frames; i++)
2635 if (masks[i]->get_width() != (int)size)
2636 PixMask::scale(masks[i], size, size);
2642 void GraphicsCache::loadProdShields()
2644 //load the production shieldset
2645 int xsize = PRODUCTION_SHIELD_WIDTH;
2646 int ysize = PRODUCTION_SHIELD_HEIGHT;
2647 std::vector<PixMask* > prodshieldpics;
2648 prodshieldpics = disassemble_row
2649 (File::getMiscFile("various/prodshieldset.png"), PRODUCTION_SHIELD_TYPES);
2650 for (unsigned int i = 0; i < PRODUCTION_SHIELD_TYPES; i++)
2652 if (prodshieldpics[i]->get_width() != xsize)
2653 PixMask::scale(prodshieldpics[i], xsize, ysize);
2654 d_prodshieldpic[i] = prodshieldpics[i];
2658 void GraphicsCache::loadMedalPics()
2660 //load the medal icons
2662 std::vector<PixMask* > medalpics;
2663 medalpics = disassemble_row(File::getMiscFile("various/medals_mask.png"),
2665 for (unsigned int i = 0; i < MEDAL_TYPES; i++)
2667 if (medalpics[i]->get_width() != ts)
2668 PixMask::scale(medalpics[i], ts, ts);
2669 d_medalpic[0][i] = medalpics[i];
2671 medalpics = disassemble_row(File::getMiscFile("various/bigmedals.png"),
2673 for (unsigned int i = 0; i < MEDAL_TYPES; i++)
2674 d_medalpic[1][i] = medalpics[i];
2677 void GraphicsCache::loadNewLevelPics()
2679 std::vector<PixMask* > half;
2680 half = disassemble_row(File::getMiscFile("various/hero-newlevel-male.png"),
2682 d_newlevel_male = half[0];
2683 d_newlevelmask_male = half[1];
2684 half = disassemble_row(File::getMiscFile("various/hero-newlevel-female.png"),
2686 d_newlevel_female = half[0];
2687 d_newlevelmask_female = half[1];
2690 void GraphicsCache::loadMoveBonusPics()
2692 //load the movement bonus icons
2693 int xsize = MOVE_BONUS_WIDTH;
2694 int ysize = MOVE_BONUS_HEIGHT;
2695 std::vector<PixMask* > movebonuspics;
2696 movebonuspics = disassemble_row(File::getMiscFile("various/movebonus.png"),
2698 for (unsigned int i = 0; i < MOVE_BONUS_TYPES; i++)
2700 if (movebonuspics[i]->get_width() != xsize)
2701 PixMask::scale(movebonuspics[i], xsize, ysize);
2702 d_movebonuspic[i] = movebonuspics[i];
2706 bool GraphicsCache::loadFlagImages(std::string filename, guint32 size, std::vector<PixMask* > &images, std::vector<PixMask* > &masks)
2708 images = disassemble_row(filename, FLAG_TYPES, true);
2709 for (unsigned int i = 0; i < FLAG_TYPES; i++)
2711 if (images[i]->get_width() != (int)size)
2712 PixMask::scale(images[i], size, size);
2715 masks = disassemble_row(filename, FLAG_TYPES, false);
2716 for (unsigned int i = 0; i < FLAG_TYPES; i++)
2718 if (masks[i]->get_width() !=(int) size)
2719 PixMask::scale(masks[i], size, size);
2724 PixMask* GraphicsCache::getMedalPic(bool large, int type)
2727 return d_medalpic[1][type];
2729 return d_medalpic[0][type];
2732 PixMask* GraphicsCache::loadImage(std::string filename, bool alpha)
2734 return PixMask::create(filename);
2737 PixMask* GraphicsCache::getMiscPicture(std::string picname, bool alpha)
2739 return loadImage(File::getMiscFile("/various/" + picname), alpha);