1 // Copyright (C) 2003, 2004, 2005, 2006, 2007 Ulf Lorenz
2 // Copyright (C) 2004, 2006 Andrea Paternesi
3 // Copyright (C) 2006-2011, 2014, 2015, 2017, 2020 Ben Asselstine
4 //
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.
9 //
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.
14 //
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
18 //  02110-1301, USA.
19 
20 #pragma once
21 #ifndef IMAGE_CACHE_H
22 #define IMAGE_CACHE_H
23 
24 #include <list>
25 #include <map>
26 #include <vector>
27 #include <string.h>
28 #include <cairomm/context.h>
29 #include "PixMaskCache.h"
30 
31 #include "player.h"
32 #include "PixMask.h"
33 #include "maptile.h"
34 #include "hero.h"
35 
36 class Road;
37 class City;
38 class Temple;
39 class Ruin;
40 class Bridge;
41 class Stack;
42 class Shieldset;
43 class SelectorPixMaskCacheItem;
44 class ArmyPixMaskCacheItem;
45 class FlagPixMaskCacheItem;
46 class CircledArmyPixMaskCacheItem;
47 class TilePixMaskCacheItem;
48 class CityPixMaskCacheItem;
49 class TowerPixMaskCacheItem;
50 class TemplePixMaskCacheItem;
51 class RuinPixMaskCacheItem;
52 class DiplomacyPixMaskCacheItem;
53 class RoadPixMaskCacheItem;
54 class FogPixMaskCacheItem;
55 class BridgePixMaskCacheItem;
56 class CursorPixMaskCacheItem;
57 class ShieldPixMaskCacheItem;
58 class ProdShieldPixMaskCacheItem;
59 class MoveBonusPixMaskCacheItem;
60 class ShipPixMaskCacheItem;
61 class PlantedStandardPixMaskCacheItem;
62 class PortPixMaskCacheItem;
63 class SignpostPixMaskCacheItem;
64 class BagPixMaskCacheItem;
65 class ExplosionPixMaskCacheItem;
66 class NewLevelPixMaskCacheItem;
67 class DefaultTileStylePixMaskCacheItem;
68 class TartanPixMaskCacheItem;
69 class EmptyTartanPixMaskCacheItem;
70 class StatusPixMaskCacheItem;
71 class GameButtonPixMaskCacheItem;
72 class DialogPixMaskCacheItem;
73 class MedalPixMaskCacheItem;
74 
75 //! Cache for generated army and map images.
76 /** Soliton class for caching army and map images
77   *
78   * With the introduction of player-specific colors, the problem of caching
79   * images has popped up. The player colors are implemented by taking an army
80   * picture and a mask, with the mask being a 16 color image, substituting
81   * the colors in the mask and blitting the mask over the army (or e.g. city)
82   * image. This takes several blits (>3, there are also things like medals
83   * to be considered) and is therefore costly.
84   *
85   * This class approaches this problem by caching formatted images. You get
86   * e.g. an army image by querying the cache, which either gives you the cached
87   * image or creates a new one. If the size is exceeded, the class will free
88   * the oldest (not used for the longest time) images until it gets below the
89   * treshold. It maintains some kind of balance between cached city pictures
90   * and cached army pictures, but the kind of balance may change, so I'll
91   * better not describe it here. :)
92   *
93   * Recently, it has been improved to cache flag pictures (showing how many
94   * armies a stack contains) as well.
95   *
96   * The maximum cache size can be changed on the fly by modifying the value in
97   * the Configuration class. However, if set too small (around 1 megabyte), this
98   * value will silently be ignored.
99   *
100   * @note For efficiency reasons, the class will not copy the surfaces it has,
101   * so DON'T MODIFY THEM unless you know what you do!
102   */
103 class ImageCache
104 {
105     public:
106   enum CursorType
107     {
108       POINTER = 0,
109       MAGNIFYING_GLASS,
110       SHIP,
111       ROOK,
112       HAND,
113       TARGET,
114       FEET,
115       RUIN,
116       SWORD,
117       QUESTION,
118       HEART,
119       GOTO_ARROW,
120       CLOSED_HAND,
121     };
122   enum GameButtonType
123     {
124       DIPLOMACY_NO_PROPOSALS = 0,
125       STACK_PARK,
126       NEXT_MOVABLE_STACK,
127       STACK_MOVE,
128       MOVE_ALL_STACKS,
129       CENTER_ON_STACK,
130       STACK_DEFEND,
131       STACK_DESELECT,
132       DIPLOMACY_NEW_PROPOSALS,
133       STACK_SEARCH,
134       END_TURN,
135       GARRISON
136     };
137   enum StatusBoxImageType
138     {
139       STATUS_CITY = 0,
140       STATUS_TREASURY,
141       STATUS_INCOME,
142       STATUS_UPKEEP,
143       STATUS_DEFENSE, //doesn't belong but we put it here anyway
144     };
145 
146   enum DialogImageType
147     {
148       DIALOG_NEXT_TURN = 0,
149       DIALOG_NEW_HERO_MALE,
150       DIALOG_NEW_HERO_FEMALE,
151       DIALOG_CONQUERED_CITY,
152       DIALOG_WINNING,
153       DIALOG_RUIN_SUCCESS,
154       DIALOG_RUIN_DEFEAT,
155       DIALOG_PARLEY_OFFERED,
156       DIALOG_PARLEY_REFUSED,
157       DIALOG_COMMENTATOR,
158     };
159 
160         //! Method for getting/creating the soliton instance.
161         static ImageCache* getInstance();
162 
163         //! Explicitly deletes the soliton instance
164         static void deleteInstance();
165 
166         //! Get the current cache size, the maximum is in Configuration::s_cacheSize
getCacheSize()167         guint32 getCacheSize() const {return d_cachesize;}
168 
169         /** Method for getting the army picture from the cache
170           *
171           * This method returns either the cached image of the given type or
172           * creates a new one and caches it. Use this method to access
173           * army images! And: Don't touch the returned surface!! For performance
174           * reasons you get the original surface which is also in the cache.
175           *
176           * The returned surface contains the correct player colors and some
177           * icons displaying the level of the unit.
178           *
179           * @param armyset      the armyset to be used
180           * @param army         the index of the army to be used
181           * @param player       the player owning the army
182           * @param medals       an array of medal types
183           * @param map          whether or not this army appears on a map
184           * @param font_size    the height of the default font, if not on map
185 	  * @param greyed       the image is greyed out; deselected/inactive.
186           * @return the image of the unit
187           */
188         PixMask* getArmyPic(guint32 armyset, guint32 army, const Player* p,
189                                 const bool* medals, bool map, guint32 font_size,
190                                 bool greyed = false);
191 	PixMask* getArmyPic(Army *a, bool greyed = false);
192         PixMask* getDialogArmyPic(Army *a, guint32 font_size, bool greyed = false);
193         PixMask* getCircledArmyPic(guint32 armyset, guint32 army,
194                                    const Player* p, const bool* medals,
195                                    bool greyed, guint32 circle_colour_id,
196                                    bool show_army, guint32 font_size);
197         PixMask *getCircledArmyPic(Army *a, bool greyed,
198                                    guint32 circle_colour_id, bool show_army,
199                                    guint32 font_size);
200 
201         /** Method for getting the shield picture from the cache
202           *
203           * This method returns either the cached image of the given type or
204           * creates a new one and caches it. Use this method to access
205           * army images! And: Don't touch the returned surface!! For performance
206           * reasons you get the original surface which is also in the cache.
207           *
208           * The returned surface contains the correct player colors and some
209           * icons displaying the level of the unit.
210           *
211           * @param shieldset    the id of the shieldset to be used
212 	  * @param type         the size of the shield: 0=sm, 1=med, 2=lg
213           * @param colour       which player the shield is for
214           * @param map          whether or not this shield appears on a map
215           * @param font_size    for map=false, to calculate relative size
216           * @return the image of the shield
217           */
218         PixMask* getShieldPic(guint32 shieldset, guint32 type, guint32 colour,
219                               bool map, guint32 font_size);
220         PixMask* getShieldPic(guint32 type, Player *p, bool map,
221                               guint32 font_size);
222 
223         /** Method for getting a ruin picture
224           *
225           * @param type         the type of the ruin
226           * @return image of the ruin
227           */
228         PixMask* getRuinPic(Ruin *r);
229         PixMask* getRuinPic(int type);
230         PixMask* getRuinPic(int type, guint32 cityset);
231 
232         /** Method for getting a diplomacy icon
233           *
234           * @param type         0 = small, or 1 = large.
235           * @param state        the diplomatic state.  e.g. peace, war, etc
236           * @font_size is the height of the default font in pixels.
237           * @return image of the icon
238           */
239         PixMask* getDiplomacyPic(int type, Player::DiplomaticState state,
240                                  guint32 font_size);
241 
242         /** Method for getting a temple picture
243           *
244           * @param type         the type of the temple
245           * @return image of the temple
246           */
247         PixMask* getTemplePic(Temple *t);
248         PixMask* getTemplePic(int type);
249         PixMask* getTemplePic(int type, guint32 cityset);
250 
251         /** Method for getting a road picture
252           *
253           * @param type         the type of the road
254           * @return image of the road
255           */
256         PixMask* getRoadPic(Road *r);
257         PixMask* getRoadPic(int type, guint32 tileset);
258         PixMask* getRoadPic(int type);
259 
260         /** Method for getting a fog picture
261           *
262           * @param type         the type of the fog
263           * @return image of the fog
264           */
265         PixMask* getFogPic(int type, guint32 tileset);
266         PixMask* getFogPic(int type);
267 
268         /** Method for getting a bridge picture
269           *
270           * @param type         the type of the bridge 0=e/w 1=n/s
271           * @return image of the bridge
272           */
273         PixMask* getBridgePic(Bridge *b);
274         PixMask* getBridgePic(int type, guint32 tileset);
275         PixMask* getBridgePic(int type);
276 
277         /** Method for getting a cursor picture
278           *
279           * @param type         the type of the cursor
280           * @font_size          the height of the default font in pixels.
281           * @return image of the cursor
282           */
283         PixMask* getCursorPic(int type, guint32 font_size);
284 
285         /** Method for getting a ship picture.  This is the picture
286 	  * that appears when the stack goes into the water.
287           *
288           * @param p            the player to colour the ship as
289           * @return image of the ship
290           */
291         PixMask* getShipPic(const Player* p);
292 
293         /** Method for getting a standard picture.  This is the picture
294 	  * that appears when the hero plants a flag..
295           *
296           * @param p            the player to colour the flag as
297           * @return image of the standard
298           */
299         PixMask* getPlantedStandardPic(const Player* p);
300 
301         /** Method for getting a port picture.  This is the picture
302 	  * that appears often as an anchor on coastal regions.
303           *
304           * @return image of the port
305           */
306         PixMask* getPortPic();
307         PixMask* getPortPic(guint32 cityset);
308 
309         /** Method for getting a signpost picture.  This is the picture
310 	  * that appears as a little tiny sign on grassy tiles.
311           *
312           * @return image of the signpost
313           */
314         PixMask* getSignpostPic();
315         PixMask* getSignpostPic(guint32 cityset);
316 
317         /** Method for getting a bag-of-items picture.  This is the picture
318 	  * that shows when a hero drops one or more items on the ground.
319           *
320           * @return image of the sack of items
321           */
322         PixMask* getBagPic();
323         PixMask* getBagPic(guint32 armyset);
324 
325         /** Method for getting an explosion picture.  This is the picture
326 	  * that shows when stacks are fighting.
327           *
328           * @return image of the explosion.
329           */
330         PixMask* getExplosionPic();
331         PixMask* getExplosionPic(guint32 tileset);
332 
333 	/** Method for getting a new-level picture.  This is the picture
334 	 * that appears when a hero gains a new level, and subsequently gets
335 	 * to increase a stat.
336 	 *
337 	 * @param p the player to colour the image as.
338          * @param gender male=1, female=2.
339          * @font_size is the height of the default font in pixels.
340 	 * @return new-level image.
341 	 */
342         PixMask* getNewLevelPic(const Player* p, guint32 gender,
343                                 guint32 font_size);
344 
345         /** Method for getting a picture that represents a type of tile style.
346          *  The parameter is related to tilestyle.h:TileStyle::Type.
347          */
348         PixMask* getDefaultTileStylePic(guint32 tilestyle_type,
349                                         guint32 tilesize);
350 
351         /** Method for getting a picture of the tartan progess bar.
352          * The image will not be any wider than width, but can be less wide.
353          */
354         PixMask* getTartanPic (const Player *p, guint32 width,
355                                Shieldset *s, guint32 font_size);
356 
357         /** Method for getting a picture of the empty tartan progess bar.
358          * The image will not be any wider than width, but can be less wide.
359          */
360         PixMask* getEmptyTartanPic (const Player *p, guint32 width,
361                                     Shieldset *s, guint32 font_size);
362 
363         /** Method for getting a city picture
364           *
365           * For simplicity we have extended the basic_image/mask style to
366           * cities as well, since it greatly reduces the number of images.
367           * Use this method solely to get city images, and don't touch the
368           * images!
369           *
370           * @param type         the level of the city; -1 returns the pic for
371           *                     the razed city
372           * @param player       the player owning the city
373 	  * @param cityset      the cityset that has the city image
374           * @return image of the described city
375           */
376         PixMask* getCityPic(int type, const Player* p, guint32 cityset);
377         /** Another method for getting a city picture
378           *
379           * Most often, we don't need such a sophisticated method. So just
380           * supply the city instance and be happy. :)
381           *
382           * @param city     the city whose picture we want to get
383           * @return image of the city
384           */
385         PixMask* getCityPic(const City* city);
386         PixMask* getCityPic(const City* city, guint32 cityset);
387 
388         /** Method for getting tower pictures.
389           *
390           * As with the other methods, use solely this method to get the tower
391           * images. And DON'T modify the images!
392           *
393           * @param p the player for which we want to get the tower
394           * @return image for the tower
395           */
396         PixMask* getTowerPic(const Player *p);
397 	PixMask* getTowerPic(const Player* p, guint32 cityset);
398         /** Method for getting flag pictures.
399           *
400           * As with the other methods, use solely this method to get the flag
401           * images. And DON'T modify the images!
402           *
403           * @param stack    the stack for which we want to get the flag
404           * @return image for the flag
405           */
406         PixMask* getFlagPic(const Stack* s);
407         PixMask* getFlagPic(const Stack* s, guint32 tileset);
408 	PixMask* getFlagPic(guint32 stack_size, const Player *p);
409         PixMask* getFlagPic(guint32 stack_size, const Player *p, guint32 tileset);
410 
411         /** Method for getting selector pictures.
412           *
413           * As with the other methods, use solely this method to get the
414           * selector images. And DON'T modify the images!
415           *
416           * @param type the frame of the selector
417           * @param p the player to draw it for
418           * @return image for the flag
419           */
420         PixMask* getSelectorPic(guint32 type, guint32 frame, const Player* p, guint32 tileset);
421 
422 	PixMask* getSelectorPic(guint32 type, guint32 frame, const Player *p);
423 
424 	PixMask* 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, guint32 shieldset, int stone_type);
425 	PixMask* 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, int stone_type);
426 
427 
428         PixMask* getMoveBonusPic(guint32 bonus, bool has_ship, guint32 font_size);
429         /** Method for getting production shield pictures.
430           *
431           * As with the other methods, use solely this method to get the
432           * shield images. And DON'T modify the images!
433           *
434           * @param type home/away/destination/source/invalid.
435 	  * one sees home/away
436 	  * normally, but when "see all" is turned on, one sees source/dest.
437           * @param prod city production is going on, true or false
438           * @return image for the shield
439 	  * note that type=source, production=false is impossible
440 	  * note that type=invalid,production=true is used to show the symbol
441 	  * that means no more units can be vectored to this city.
442           */
443         PixMask* getProdShieldPic(guint32 type, bool prod);
444 
445         PixMask* getMedalPic(bool large, guint32 type, guint32 font_size);
446 
447         //! Erase cached graphics.
448         void reset();
449 
450         //these routines get a base image, not a cached image.
451         PixMask* getDiplomacyImage(int type, Player::DiplomaticState state);
452         PixMask* getCursorImage(int type);
453         PixMask *getProdShieldImage(guint32 type);
454         PixMask* getMoveBonusImage(guint32 type);
455         PixMask* getDefaultTileStyleImage(guint32 type);
456         PixMask* getMedalImage(bool large, int type);
457         PixMask *getNewLevelImage(bool female, bool mask);
458         PixMask* getSmallRuinedCityImage();
459 	//! Return a small hero picture, either white (active==true) or black.
460         PixMask* getSmallHeroImage(bool active);
461         PixMask* getSmallBagImage();
462         PixMask*getSmallTempleImage();
463         PixMask*getSmallRuinExploredImage();
464         PixMask* getSmallRuinUnexploredImage();
465         PixMask* getSmallStrongholdUnexploredImage();
466         //! get an image for one of the buttons on the main game window.
467         PixMask* getStatusPic(guint32 type, guint32 font_size);
468         /** Method for getting main screen game button pictures.
469          *
470          * @param type is one of the enums.
471          * @font_size is the height of the default font in pixels.
472          */
473         PixMask* getGameButtonPic(guint32 type, guint32 font_size);
474         PixMask* getDialogPic(guint32 type, guint32 font_size);
475         PixMask* getWaypointImage(guint32 type);
476 
477         PixMask* getNextTurnPic ();
478         PixMask* getCityDefeatedPic ();
479         PixMask* getWinningPic();
480         PixMask* getHeroPic (Hero::Gender gender);
481         PixMask* getRuinSuccessPic();
482         PixMask* getRuinDefeatPic();
483         PixMask *getParleyOfferedPic();
484         PixMask *getParleyRefusedPic();
485         PixMask *getCommentatorPic ();
486 
487         PixMask* getGameButtonImage(guint32 type);
488 
489 	static PixMask* applyMask(PixMask* image, PixMask* mask, const Player* p);
490 	static PixMask* applyMask(PixMask* image, PixMask* mask, Gdk::RGBA colour);
491 
492 	static PixMask* greyOut(PixMask* image);
493 
494         static PixMask* circled(PixMask* image, Gdk::RGBA colour, bool coloured = true, double width_percent = 75.0);
495         static void draw_circle(Cairo::RefPtr<Cairo::Context> cr, double width_percent, int width, int height, Gdk::RGBA colour, bool coloured = true, bool mask = false);
496         static PixMask* loadMiscImage(Glib::ustring pngfile);
497 
498         static int calculate_width_from_adjusted_height (PixMask *p, double new_height);
499         static void add_underline (PixMask **p, Gdk::RGBA color, guint32 font_size);
500     private:
501         ImageCache();
502         ~ImageCache();
503 
504         //! Checks if the cache has exceeded the maximum size and reduce it.
505         void checkPictures();
506 
507         bool loadDiplomacyImages();
508         bool loadCursorImages();
509         bool loadProdShieldImages();
510         bool loadMoveBonusImages();
511         bool loadNewLevelImages();
512         bool loadMedalImages(Glib::ustring sm, Glib::ustring lg);
513         bool loadDefaultTileStyleImages();
514         bool loadWaypointImages();
515         bool loadGameButtonImages();
516 
517         //the data
518         static ImageCache* s_instance;
519 
520         guint32 d_cachesize;
521 
522         PixMaskCache<SelectorPixMaskCacheItem> selectorcache;
523         PixMaskCache<ArmyPixMaskCacheItem> armycache;
524         PixMaskCache<FlagPixMaskCacheItem> flagcache;
525         PixMaskCache<CircledArmyPixMaskCacheItem> circledarmycache;
526         PixMaskCache<TilePixMaskCacheItem> tilecache;
527         PixMaskCache<CityPixMaskCacheItem> citycache;
528         PixMaskCache<TowerPixMaskCacheItem> towercache;
529         PixMaskCache<TemplePixMaskCacheItem> templecache;
530         PixMaskCache<RuinPixMaskCacheItem> ruincache;
531         PixMaskCache<DiplomacyPixMaskCacheItem> diplomacycache;
532         PixMaskCache<RoadPixMaskCacheItem> roadcache;
533         PixMaskCache<FogPixMaskCacheItem> fogcache;
534         PixMaskCache<BridgePixMaskCacheItem> bridgecache;
535         PixMaskCache<CursorPixMaskCacheItem> cursorcache;
536         PixMaskCache<ShieldPixMaskCacheItem> shieldcache;
537         PixMaskCache<ProdShieldPixMaskCacheItem> prodshieldcache;
538         PixMaskCache<MoveBonusPixMaskCacheItem> movebonuscache;
539         PixMaskCache<ShipPixMaskCacheItem> shipcache;
540         PixMaskCache<PlantedStandardPixMaskCacheItem> plantedstandardcache;
541         PixMaskCache<PortPixMaskCacheItem> portcache;
542         PixMaskCache<SignpostPixMaskCacheItem> signpostcache;
543         PixMaskCache<BagPixMaskCacheItem> bagcache;
544         PixMaskCache<ExplosionPixMaskCacheItem> explosioncache;
545         PixMaskCache<NewLevelPixMaskCacheItem> newlevelcache;
546         PixMaskCache<DefaultTileStylePixMaskCacheItem> defaulttilestylecache;
547         PixMaskCache<TartanPixMaskCacheItem> tartancache;
548         PixMaskCache<EmptyTartanPixMaskCacheItem> emptytartancache;
549         PixMaskCache<StatusPixMaskCacheItem> statuscache;
550         PixMaskCache<GameButtonPixMaskCacheItem> gamebuttoncache;
551         PixMaskCache<DialogPixMaskCacheItem> dialogcache;
552         PixMaskCache<MedalPixMaskCacheItem> medalcache;
553 
554         PixMask* d_diplomacy[2][DIPLOMACY_TYPES];
555         PixMask* d_cursor[CURSOR_TYPES];
556         PixMask* d_prodshield[PRODUCTION_SHIELD_TYPES];
557         PixMask* d_movebonus[MOVE_BONUS_TYPES];
558 	PixMask *d_newlevel_male;
559 	PixMask *d_newlevelmask_male;
560 	PixMask *d_newlevel_female;
561 	PixMask *d_newlevelmask_female;
562         PixMask *d_default_tilestyles[DEFAULT_TILESTYLE_TYPES];
563         PixMask* d_medal[2][MEDAL_TYPES];
564 	PixMask* d_smallruinedcity;
565 	PixMask* d_smallhero;
566 	PixMask* d_smallbag;
567 	PixMask* d_smallinactivehero;
568 	PixMask* d_small_ruin_unexplored;
569 	PixMask* d_small_stronghold_unexplored;
570 	PixMask* d_small_ruin_explored;
571 	PixMask* d_small_temple;
572         PixMask *d_waypoint[NUM_WAYPOINTS];
573         PixMask *d_gamebuttons[NUM_GAME_BUTTON_IMAGES];
574         PixMask *d_nextturn;
575         PixMask *d_citydefeated;
576         PixMask *d_winning;
577         PixMask *d_malehero;
578         PixMask *d_femalehero;
579         PixMask *d_ruinsuccess;
580         PixMask *d_ruindefeat;
581         PixMask *d_parleyoffered;
582         PixMask *d_parleyrefused;
583         PixMask *d_commentator;
584 };
585 
586 //! Helper class for selector box items in the ImageCache.
587 /**
588  * These selector box images appear around the active stack.
589  * It's a set of frames for an animation.
590  */
591 class SelectorPixMaskCacheItem
592 {
593 public:
594     static PixMask *generate(SelectorPixMaskCacheItem item);
595     static bool loadSelectorImages(Glib::ustring filename, guint32 size, std::vector<PixMask* > &images, std::vector<PixMask* > &masks, bool scale);
596     static bool loadSelectors(PixMask *p, guint32 size, std::vector<PixMask* > &images, std::vector<PixMask* > &masks, bool scale);
597     int comp(const SelectorPixMaskCacheItem item) const;
598     bool operator == (const SelectorPixMaskCacheItem &c) {return !comp(c);};
599     bool operator < (const SelectorPixMaskCacheItem &c) const {return comp(c)<0;};
600     guint32 tileset;
601     guint32 type;
602     guint32 frame;
603     guint32 player_id;
604 };
605 
606 //! Helper class for army items in the ImageCache.
607 /**
608  * These army images appear on the big map as the leader of a stack.
609  */
610 class ArmyPixMaskCacheItem
611 {
612 public:
613     static PixMask *generate(ArmyPixMaskCacheItem item);
614     int comp(const ArmyPixMaskCacheItem item) const;
615     bool operator == (const ArmyPixMaskCacheItem &c) {return !comp(c);};
616     bool operator < (const ArmyPixMaskCacheItem &c) const {return comp(c)<0;};
617     guint32 armyset;
618     guint32 army_id;
619     guint32 player_id;
620     bool medals[3];
621     bool map;
622     guint32 font_size;
623     bool greyed;
624 };
625 
626 //! Helper class for stack flag items in the ImageCache.
627 /**
628  * These stack flag images have 8 different sizes, and appear on the big map.
629  */
630 class FlagPixMaskCacheItem
631 {
632 public:
633     static PixMask *generate(FlagPixMaskCacheItem item);
634     static bool loadFlagImages(Glib::ustring filename, guint32 size, std::vector<PixMask* > &images, std::vector<PixMask* > &masks, bool scale);
635     static bool loadFlagImages(PixMask *p, guint32 size, std::vector<PixMask* > &images, std::vector<PixMask* > &masks, bool scale);
636     int comp(const FlagPixMaskCacheItem item) const;
637     bool operator == (const FlagPixMaskCacheItem &c) {return !comp(c);};
638     bool operator < (const FlagPixMaskCacheItem &c) const {return comp(c)<0;};
639     guint32 tileset;
640     guint32 size;
641     guint32 player_id;
642 };
643 
644 //! Helper class for circled army items in the ImageCache.
645 /**
646  * These circled army images appear in various places in the gui.
647  * It's just an army unit with a coloured circle behind it.
648  */
649 class CircledArmyPixMaskCacheItem
650 {
651 public:
652     static PixMask *generate(CircledArmyPixMaskCacheItem item);
653     int comp(const CircledArmyPixMaskCacheItem item) const;
654     bool operator == (const CircledArmyPixMaskCacheItem &c) {return !comp(c);};
655     bool operator < (const CircledArmyPixMaskCacheItem &c) const {return comp(c)<0;};
656     guint32 armyset;
657     guint32 army_id;
658     guint32 player_id;
659     bool medals[3];
660     bool greyed;
661     guint32 circle_colour_id;
662     bool show_army;
663     guint32 font_size;
664 };
665 
666 //! Helper class for big map tile items in the ImageCache.
667 /**
668  * These tile images are the almalgmation of all the things on a given tile of
669  * the big map.
670  */
671 class TilePixMaskCacheItem
672 {
673 public:
674     static PixMask *generate(TilePixMaskCacheItem item);
675     int comp(const TilePixMaskCacheItem item) const;
676     bool operator == (const TilePixMaskCacheItem &c) {return !comp(c);};
677     bool operator < (const TilePixMaskCacheItem &c) const {return comp(c)<0;};
678   int tile_style_id;
679   int fog_type_id;
680   bool has_bag;
681   bool has_standard;
682   int standard_player_id;
683   int stack_size; //flag size
684   int stack_player_id;
685   int army_type_id;
686   bool has_tower;
687   bool has_ship;
688   Maptile::Building building_type;
689   int building_subtype;
690   Vector<int> building_tile;
691   int building_player_id;
692   guint32 tilesize;
693   bool has_grid;
694   guint32 tileset;
695   guint32 cityset;
696   guint32 shieldset;
697   int stone_type;
698 };
699 
700 //! Helper class for city items in the ImageCache.
701 /**
702  * These city images appear on the big map.
703  */
704 class CityPixMaskCacheItem
705 {
706 public:
707     static PixMask *generate(CityPixMaskCacheItem item);
708     int comp(const CityPixMaskCacheItem item) const;
709     bool operator == (const CityPixMaskCacheItem &c) {return !comp(c);};
710     bool operator < (const CityPixMaskCacheItem &c) const {return comp(c)<0;};
711     guint32 cityset;
712     int type;
713     guint32 player_id;
714 };
715 
716 //! Helper class for tower items in the ImageCache.
717 /**
718  * These tower images appear on the big map when a stack goes into defend mode.
719  */
720 class TowerPixMaskCacheItem
721 {
722 public:
723     static PixMask *generate(TowerPixMaskCacheItem item);
724     int comp(const TowerPixMaskCacheItem item) const;
725     bool operator == (const TowerPixMaskCacheItem &c) {return !comp(c);};
726     bool operator < (const TowerPixMaskCacheItem &c) const {return comp(c)<0;};
727     guint32 cityset;
728     guint32 player_id;
729 };
730 
731 //! Helper class for temple items in the ImageCache.
732 /**
733  * These temple images appear on the big map.
734  */
735 class TemplePixMaskCacheItem
736 {
737 public:
738     static PixMask *generate(TemplePixMaskCacheItem item);
739     int comp(const TemplePixMaskCacheItem item) const;
740     bool operator == (const TemplePixMaskCacheItem &c) {return !comp(c);};
741     bool operator < (const TemplePixMaskCacheItem &c) const {return comp(c)<0;};
742     guint32 cityset;
743     int type;
744 };
745 
746 //! Helper class for ruin items in the ImageCache.
747 /**
748  * These ruin images appear on the big map.
749  */
750 class RuinPixMaskCacheItem
751 {
752 public:
753     static PixMask *generate(RuinPixMaskCacheItem item);
754     int comp(const RuinPixMaskCacheItem item) const;
755     bool operator == (const RuinPixMaskCacheItem &c) {return !comp(c);};
756     bool operator < (const RuinPixMaskCacheItem &c) const {return comp(c)<0;};
757     guint32 cityset;
758     int type;
759 };
760 
761 //! Helper class for diplomacy icon items in the ImageCache.
762 /**
763  * These diplomacy icons appear in the diplomacy dialog.
764  */
765 class DiplomacyPixMaskCacheItem
766 {
767 public:
768     static PixMask *generate(DiplomacyPixMaskCacheItem item);
769     int comp(const DiplomacyPixMaskCacheItem item) const;
770     bool operator == (const DiplomacyPixMaskCacheItem &c) {return !comp(c);};
771     bool operator < (const DiplomacyPixMaskCacheItem &c) const {return comp(c)<0;};
772     int type;
773     Player::DiplomaticState state;
774     guint32 font_size;
775 };
776 
777 //! Helper class for road items in the ImageCache.
778 /**
779  * These are the road images that appear on the big map.
780  */
781 class RoadPixMaskCacheItem
782 {
783 public:
784     static PixMask *generate(RoadPixMaskCacheItem item);
785     int comp(const RoadPixMaskCacheItem item) const;
786     bool operator == (const RoadPixMaskCacheItem &c) {return !comp(c);};
787     bool operator < (const RoadPixMaskCacheItem &c) const {return comp(c)<0;};
788     guint32 tileset;
789     int type;
790 };
791 
792 //! Helper class for fog items in the ImageCache.
793 /**
794  * These are the black fog images that appear on top of the big map.
795  * E.g. more of the map gets exposed when army units move around.
796  */
797 class FogPixMaskCacheItem
798 {
799 public:
800     static PixMask *generate(FogPixMaskCacheItem item);
801     int comp(const FogPixMaskCacheItem item) const;
802     bool operator == (const FogPixMaskCacheItem &c) {return !comp(c);};
803     bool operator < (const FogPixMaskCacheItem &c) const {return comp(c)<0;};
804     guint32 tileset;
805     int type;
806 };
807 
808 //! Helper class for bridge items in the ImageCache.
809 /**
810  * These are the bridge images that appear on the big map.
811  */
812 class BridgePixMaskCacheItem
813 {
814 public:
815     static PixMask *generate(BridgePixMaskCacheItem item);
816     int comp(const BridgePixMaskCacheItem item) const;
817     bool operator == (const BridgePixMaskCacheItem &c) {return !comp(c);};
818     bool operator < (const BridgePixMaskCacheItem &c) const {return comp(c)<0;};
819     guint32 tileset;
820     int type;
821 };
822 
823 //! Helper class for cursor items in the ImageCache.
824 /**
825  * These are the black and white mouse cursor images.
826  */
827 class CursorPixMaskCacheItem
828 {
829 public:
830     static PixMask *generate(CursorPixMaskCacheItem item);
831     int comp(const CursorPixMaskCacheItem item) const;
832     bool operator == (const CursorPixMaskCacheItem &c) {return !comp(c);};
833     bool operator < (const CursorPixMaskCacheItem &c) const {return comp(c)<0;};
834     int type;
835     guint32 font_size;
836 };
837 
838 //! Helper class for shield items in the ImageCache.
839 /**
840  * These shield images include the small, medium and large shield images.
841  */
842 class ShieldPixMaskCacheItem
843 {
844 public:
845     static PixMask *generate(ShieldPixMaskCacheItem item);
846     int comp(const ShieldPixMaskCacheItem item) const;
847     bool operator == (const ShieldPixMaskCacheItem &c) {return !comp(c);};
848     bool operator < (const ShieldPixMaskCacheItem &c) const {return comp(c)<0;};
849     guint32 shieldset;
850     guint32 type;
851     guint32 colour;
852     bool map;
853     guint32 font_size;
854 };
855 
856 //! Helper class for production icon items in the ImageCache.
857 /**
858  * these icons appear on the smallmap.
859  */
860 class ProdShieldPixMaskCacheItem
861 {
862 public:
863     static PixMask *generate(ProdShieldPixMaskCacheItem item);
864     int comp(const ProdShieldPixMaskCacheItem item) const;
865     bool operator == (const ProdShieldPixMaskCacheItem &c) {return !comp(c);};
866     bool operator < (const ProdShieldPixMaskCacheItem &c) const {return comp(c)<0;};
867     guint32 type;
868     bool prod;
869 };
870 
871 //! Helper class for movement bonus icon items in the ImageCache.
872 /**
873  * These icons appear in the gui, on stack tip infos, or in the stack box.
874  */
875 class MoveBonusPixMaskCacheItem
876 {
877 public:
878     static PixMask *generate(MoveBonusPixMaskCacheItem item);
879     int comp(const MoveBonusPixMaskCacheItem item) const;
880     bool operator == (const MoveBonusPixMaskCacheItem &c) {return !comp(c);};
881     bool operator < (const MoveBonusPixMaskCacheItem &c) const {return comp(c)<0;};
882     guint32 type; // 0=empty, 1=trees, 2=foothills, 3=hills+trees, 4=fly, 5=boat
883     guint32 font_size;
884 };
885 
886 //! Helper class for boat items in the ImageCache.
887 /**
888  * ship images are for when a stack is in a boat.
889  * one ship image per army set, and drawn in the player's colour.
890  */
891 class ShipPixMaskCacheItem
892 {
893 public:
894     static PixMask *generate(ShipPixMaskCacheItem item);
895     int comp(const ShipPixMaskCacheItem item) const;
896     bool operator == (const ShipPixMaskCacheItem &c) {return !comp(c);};
897     bool operator < (const ShipPixMaskCacheItem &c) const {return comp(c)<0;};
898     guint32 player_id;
899     guint32 armyset;
900 };
901 
902 //! Helper class for planted standard items in the ImageCache.
903 /**
904  * planted standard images are for when the hero plants a flag on the big map.
905  */
906 class PlantedStandardPixMaskCacheItem
907 {
908 public:
909     static PixMask *generate(PlantedStandardPixMaskCacheItem item);
910     int comp(const PlantedStandardPixMaskCacheItem item) const;
911     bool operator == (const PlantedStandardPixMaskCacheItem &c) {return !comp(c);};
912     bool operator < (const PlantedStandardPixMaskCacheItem &c) const {return comp(c)<0;};
913     guint32 player_id;
914     guint32 armyset;
915 };
916 
917 //! Helper class for port items in the ImageCache.
918 /**
919  * port images are for the ship loading/unloading points on the big map.
920  */
921 class PortPixMaskCacheItem
922 {
923 public:
924     static PixMask *generate(PortPixMaskCacheItem item);
925     int comp(const PortPixMaskCacheItem item) const;
926     bool operator == (const PortPixMaskCacheItem &c) {return !comp(c);};
927     bool operator < (const PortPixMaskCacheItem &c) const {return comp(c)<0;};
928   guint32 cityset;
929 };
930 
931 //! Helper class for signpost items in the ImageCache.
932 /**
933  * signpost images are for the signs on the big map.
934  */
935 class SignpostPixMaskCacheItem
936 {
937 public:
938     static PixMask *generate(SignpostPixMaskCacheItem item);
939     int comp(const SignpostPixMaskCacheItem item) const;
940     bool operator == (const SignpostPixMaskCacheItem &c) {return !comp(c);};
941     bool operator < (const SignpostPixMaskCacheItem &c) const {return comp(c)<0;};
942   guint32 cityset;
943 };
944 
945 //! Helper class for bag items in the ImageCache.
946 /**
947  * Bags are the things that hold item objects on the big map.
948  * There is one bag image per army set.
949  */
950 class BagPixMaskCacheItem
951 {
952 public:
953     static PixMask *generate(BagPixMaskCacheItem item);
954     int comp(const BagPixMaskCacheItem item) const;
955     bool operator == (const BagPixMaskCacheItem &c) {return !comp(c);};
956     bool operator < (const BagPixMaskCacheItem &c) const {return comp(c)<0;};
957     guint32 armyset;
958 };
959 
960 //! Helper class for explosion items in the ImageCache.
961 /**
962  * Explosion images appear on the big map and in the fight window.
963  * Sometimes they appear in a 2x2 tile size, and sometimes in a 1x1 tile size.
964  */
965 class ExplosionPixMaskCacheItem
966 {
967 public:
968     static PixMask *generate(ExplosionPixMaskCacheItem item);
969     int comp(const ExplosionPixMaskCacheItem item) const;
970     bool operator == (const ExplosionPixMaskCacheItem &c) {return !comp(c);};
971     bool operator < (const ExplosionPixMaskCacheItem &c) const {return comp(c)<0;};
972     guint32 tileset;
973 };
974 
975 //! Helper class for "new level" items in the ImageCache.
976 /**
977  * New Level images are full-body images of the hero who is levelling up.  There
978  * is a male image and a female image.
979  */
980 class NewLevelPixMaskCacheItem
981 {
982 public:
983     static PixMask *generate(NewLevelPixMaskCacheItem item);
984     int comp(const NewLevelPixMaskCacheItem item) const;
985     bool operator == (const NewLevelPixMaskCacheItem &c) {return !comp(c);};
986     bool operator < (const NewLevelPixMaskCacheItem &c) const {return comp(c)<0;};
987     guint32 player_id;
988     guint32 gender;
989     guint32 font_size;
990 };
991 
992 //! Helper class for default tile style items in the ImageCache.
993 /**
994  * "default tile style" images are the black and white representations of TileStyle::Type.
995  */
996 class DefaultTileStylePixMaskCacheItem
997 {
998 public:
999     static PixMask *generate(DefaultTileStylePixMaskCacheItem item);
1000     int comp(const DefaultTileStylePixMaskCacheItem item) const;
1001     bool operator == (const DefaultTileStylePixMaskCacheItem &c) {return !comp(c);};
1002     bool operator < (const DefaultTileStylePixMaskCacheItem &c) const {return comp(c)<0;};
1003 public:
1004     guint32 tilestyle_type;
1005     guint32 tilesize;
1006 };
1007 
1008 //! Helper class for tartan progress bar images in the ImageCache.
1009 /**
1010  * These images appear on the screen when the computer player is moving
1011  * to show how much more they have yet to move.
1012  */
1013 class TartanPixMaskCacheItem
1014 {
1015 public:
1016     static PixMask *generate(TartanPixMaskCacheItem item);
1017     static void calculateWidth(guint32 iwidth, PixMask *left, PixMask *center, PixMask *right, guint32 &width, guint32 &centers, bool &include_right);
1018     int comp(const TartanPixMaskCacheItem item) const;
1019     bool operator == (const TartanPixMaskCacheItem &c) {return !comp(c);};
1020     bool operator < (const TartanPixMaskCacheItem &c) const {return comp(c)<0;};
1021     guint32 width;
1022     guint32 player_id;
1023     guint32 shieldset;
1024     guint32 font_size;
1025 };
1026 
1027 //! Helper class for empty tartan progress bar images in the ImageCache.
1028 /**
1029  * These images appear on the screen when the computer player is moving
1030  * to show how much more they have yet to move.
1031  */
1032 class EmptyTartanPixMaskCacheItem
1033 {
1034 public:
1035     static PixMask *generate(EmptyTartanPixMaskCacheItem item);
1036     int comp(const EmptyTartanPixMaskCacheItem item) const;
1037     bool operator == (const EmptyTartanPixMaskCacheItem &c) {return !comp(c);};
1038     bool operator < (const EmptyTartanPixMaskCacheItem &c) const {return comp(c)<0;};
1039     guint32 width;
1040     guint32 player_id;
1041     guint32 shieldset;
1042     guint32 font_size;
1043 };
1044 
1045 //! Helper class for status images in the ImageCache.
1046 /**
1047  * These status images include city, treasury, upkeep and income.
1048  */
1049 class StatusPixMaskCacheItem
1050 {
1051 public:
1052     static PixMask *generate(StatusPixMaskCacheItem item);
1053     int comp(const StatusPixMaskCacheItem item) const;
1054     bool operator == (const StatusPixMaskCacheItem &c) {return !comp(c);};
1055     bool operator < (const StatusPixMaskCacheItem &c) const {return comp(c)<0;};
1056     guint32 type;
1057     guint32 font_size;
1058 };
1059 
1060 //! Helper class for the main screen button images in the ImageCache.
1061 /**
1062  * These images include end turn, move all stacks, park, search and so on.
1063  */
1064 class GameButtonPixMaskCacheItem
1065 {
1066 public:
1067     static PixMask *generate(GameButtonPixMaskCacheItem item);
1068     int comp(const GameButtonPixMaskCacheItem item) const;
1069     bool operator == (const GameButtonPixMaskCacheItem &c) {return !comp(c);};
1070     bool operator < (const GameButtonPixMaskCacheItem &c) const {return comp(c)<0;};
1071     guint32 type;
1072     guint32 font_size;
1073 };
1074 
1075 //! Helper class for the various images that appear on dialogs.
1076 /**
1077  * These images include next turn, new hero, conquered city and so on.
1078  */
1079 class DialogPixMaskCacheItem
1080 {
1081 public:
1082     static PixMask *generate(DialogPixMaskCacheItem item);
1083     int comp(const DialogPixMaskCacheItem item) const;
1084     bool operator == (const DialogPixMaskCacheItem &c) {return !comp(c);};
1085     bool operator < (const DialogPixMaskCacheItem &c) const {return comp(c)<0;};
1086     guint32 type;
1087     guint32 font_size;
1088 };
1089 
1090 //! Helper class for the medal images in the ImageCache.
1091 /**
1092  * These images include the tiny medals that get awarded to armies,
1093  * and then the large ones that appear on dialogs..
1094  */
1095 class MedalPixMaskCacheItem
1096 {
1097 public:
1098     static PixMask *generate(MedalPixMaskCacheItem item);
1099     int comp(const MedalPixMaskCacheItem item) const;
1100     bool operator == (const MedalPixMaskCacheItem &c) {return !comp(c);};
1101     bool operator < (const MedalPixMaskCacheItem &c) const {return comp(c)<0;};
1102     bool large;
1103     guint32 type;
1104     guint32 font_size;
1105 };
1106 
1107 #endif
1108