1 /*
2  *  This file is part of Dune Legacy.
3  *
4  *  Dune Legacy is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation, either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  Dune Legacy is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with Dune Legacy.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MAPCHOICE_H
19 #define MAPCHOICE_H
20 
21 #include "MenuBase.h"
22 #include <DataTypes.h>
23 #include <GUI/dune/MessageTicker.h>
24 #include <misc/draw_util.h>
25 #include <misc/BlendBlitter.h>
26 #include <mmath.h>
27 #include <vector>
28 #include <SDL.h>
29 
30 #define MAPCHOICESTATE_FADEINPLANET 0
31 #define MAPCHOICESTATE_SHOWPLANET   1
32 #define MAPCHOICESTATE_BLENDPLANET  2
33 #define MAPCHOICESTATE_SHOWMAPONLY  3
34 #define MAPCHOICESTATE_BLENDMAP     4
35 #define MAPCHOICESTATE_BLENDING     5
36 #define MAPCHOICESTATE_ARROWS       6
37 #define MAPCHOICESTATE_BLINKING     7
38 
39 class MapChoice : public MenuBase
40 {
41 public:
42     MapChoice(int newHouse, unsigned int lastMission, Uint32 alreadyPlayedRegions);
43     virtual ~MapChoice();
44 
45     virtual int showMenu();
46 
getSelectedMission()47     inline int getSelectedMission() const {
48         int regionIndex;
49         for(regionIndex = 0; regionIndex < 4; regionIndex++) {
50             if(group[lastScenario].attackRegion[regionIndex].regionNum == selectedRegion) {
51                 break;
52             }
53         }
54 
55         int newMission;
56         if(lastScenario <= 7) {
57             newMission = (lastScenario-1) * 3 + 2 + regionIndex;
58         } else if(lastScenario == 8) {
59             newMission = (lastScenario-1) * 3 - 1 + 2 + regionIndex;
60         } else {
61             THROW(std::runtime_error, "lastScenario = %u is no valid scenario number!", lastScenario);
62         }
63         return newMission;
64     };
65 
getAlreadyPlayedRegions()66     inline Uint32 getAlreadyPlayedRegions() const { return alreadyPlayedRegions; }
67 
68     void drawSpecificStuff();
69     bool doInput(SDL_Event &event);
70 
71 private:
72     void createMapSurfaceWithPieces(unsigned int scenario);
73     void loadINI();
74 
75 private:
76     struct TGroup {
77         std::vector<int> newRegion[NUM_HOUSES];
78 
79         struct TAttackRegion {
80             int regionNum;
81             int arrowNum;
82             Coord arrowPosition;
83         } attackRegion[4];
84 
85         struct TText {
86             std::string message;
87             int region;     ///< when this region is changed, this message will appear.
88         };
89 
90         std::vector<TText> text;
91     } group[9];
92 
93     int house;
94     unsigned int lastScenario;
95     Uint32 alreadyPlayedRegions;
96     SDL_Surface* mapSurface;
97     SDL_Texture* mapTexture;
98     Coord piecePosition[28];
99     BlendBlitter* curBlendBlitter;
100     unsigned int curHouse2Blit;
101     unsigned int curRegion2Blit;
102     bool bFastBlending;
103     int mapChoiceState;
104     int selectedRegion;
105     Uint32  selectionTime;
106     Uint32  stateSwitchTime;
107     MessageTicker  msgticker;
108 
109     SDL_Rect centerAreaRect;
110 };
111 
112 #endif //MAPCHOICE_H
113