1 /*
2  *  Open Fodder
3  *  ---------------
4  *
5  *  Copyright (C) 2008-2018 Open Fodder
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License along
18  *  with this program; if not, write to the Free Software Foundation, Inc.,
19  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22 
23 enum ePhaseObjective {
24     eObjective_None = 0,
25     eObjective_Kill_All_Enemy = 1,
26     eObjective_Destroy_Enemy_Buildings = 2,
27     eObjective_Rescue_Hostages = 3,
28     eObjective_Protect_Civilians = 4,
29     eObjective_Kidnap_Leader = 5,
30     eObjective_Destroy_Factory = 6,
31     eObjective_Destroy_Computer = 7,
32     eObjective_Get_Civilian_Home = 8,
33     eObjective_Activate_All_Switches = 9,        // CF2
34     eObjective_Rescue_Hostage = 10,              // CF2: The CF2 engine has this as goal 3 instead of 10, and vica versa
35 };
36 
37 struct sAggression {
38     int16 mMin;
39     int16 mMax;
40 
getAveragesAggression41     int16 getAverage() const {
42 
43         return (mMin + mMax) / 2;
44     }
45 
sAggressionsAggression46     sAggression() {
47         mMin = 4;
48         mMax = 8;
49     }
sAggressionsAggression50 	sAggression(int16 pMin, int16 pMax) {
51 		mMin = pMin;
52 		mMax = pMax;
53 	}
54 
getMinsAggression55 	int16 getMin() const { return mMin; }
setMinsAggression56 	void setMin(const int16& pMin) { mMin = pMin; }
getMaxsAggression57 	int16 getMax() const { return mMax; }
setMaxsAggression58 	void setMax(const int16& pMax) { mMax = pMax; }
59 };
60 
61 class cPhase {
62 public:
63     sAggression mAggression;
64     std::string mName;
65     std::string mMapFilename;
66     std::vector<ePhaseObjective> mGoals;
67 
68     int16       mGrenades;
69     int16       mRockets;
70 
cPhase()71     cPhase() {
72         mGrenades = -1;
73         mRockets = -1;
74     }
75 
SetName(const std::string & pName)76 	void SetName(const std::string& pName) {
77 		mName = pName;
78 	}
79 
GetName() const80     std::string GetName() const {
81         std::string Name = mName;
82         transform(Name.begin(), Name.end(), Name.begin(), toupper);
83         return Name;
84     }
85 
SetMapFilename(const std::string & pMapFilename)86 	void SetMapFilename(const std::string& pMapFilename) {
87 		mMapFilename = pMapFilename;
88 	}
89 
GetMapFilename() const90 	std::string GetMapFilename() const {
91 		return mMapFilename;
92 	}
93 
SetGoal(ePhaseObjective pGoal,int pValue)94     void SetGoal(ePhaseObjective pGoal, int pValue) {
95         if (pValue)
96             AddGoal(pGoal);
97         else
98             RemoveGoal(pGoal);
99     }
100 
AddGoal(ePhaseObjective pGoal)101     void AddGoal(ePhaseObjective pGoal) {
102 
103         if (std::find(mGoals.begin(), mGoals.end(), pGoal) == mGoals.end())
104             mGoals.push_back(pGoal);
105     }
106 
RemoveGoal(ePhaseObjective pGoal)107     void RemoveGoal(ePhaseObjective pGoal) {
108 
109         auto Goal = std::find(mGoals.begin(), mGoals.end(), pGoal);
110         if (Goal != mGoals.end())
111             mGoals.erase(Goal);
112     }
113 
ClearGoals()114 	void ClearGoals() {
115 		mGoals.clear();
116 	}
117 
SetAggression(const int16 & pMin,const int16 & pMax)118 	void SetAggression(const int16& pMin, const int16& pMax) {
119 		mAggression.setMin(pMin);
120 		mAggression.setMax(pMax);
121 	}
122 
SetMinAggression(const int16 & pMin)123 	void SetMinAggression(const int16& pMin) {
124 		mAggression.setMin(pMin);
125 	}
126 
SetMaxAggression(const int16 & pMax)127 	void SetMaxAggression(const int16& pMax) {
128 		mAggression.setMax(pMax);
129 	}
130 };
131 
132 class cMission {
133 public:
134     std::string mName;
135     std::vector<std::shared_ptr<cPhase>> mPhases;
136 
GetName() const137     std::string GetName() const {
138         std::string Name = mName;
139         transform(Name.begin(), Name.end(), Name.begin(), toupper);
140         return Name;
141     }
142 
SetName(const std::string & pName)143 	void SetName(const std::string &pName) {
144 		mName = pName;
145 	}
146 
PhaseGet(size_t pPhase)147     std::shared_ptr<cPhase> PhaseGet(size_t pPhase) {
148         if (!pPhase)
149             pPhase = 1;
150 
151         if (!mPhases.size() || pPhase > mPhases.size())
152             return 0;
153 
154         return mPhases[pPhase - 1];
155     }
156 
NumberOfPhases() const157     size_t NumberOfPhases() const { return mPhases.size(); }
158 };
159 
160 class cCampaign {
161 private:
162     std::string                             mPath;
163     std::string                             mName;
164     std::string                             mAuthor;
165 
166     std::vector<std::shared_ptr<cMission>>  mMissions;
167 
168     bool mIsCustomCampaign;
169     bool mUseCustomPath;
170     bool mIsRandom;
171     bool mIsCustomMap;
172 
173 protected:
174 
175     bool LoadCustomMap(const std::string& pMapName);
176 
177 public:
178 
179     cCampaign();
180 
181     void Clear(const std::string& pName = "", const bool pDirectPath = false);
182 
183 	bool LoadCustomMapFromPath(const std::string& pMapName);
184 
185     bool LoadCampaign(const std::string& pName, bool pCustom, bool pDirectPath = false);
186     bool SaveCampaign();
187 
188 
189     std::string GetPathToCampaign() const;
190     std::string GetPathToFile(const std::string& pName) const;
191     std::string GetPath(const bool pTrailingSeperator = true) const;
192 
193 	std::shared_ptr<cMap> getCMap(std::shared_ptr<cPhase> pPhase) const;
194 
195 	tSharedBuffer getMap(std::shared_ptr<cPhase> pPhase) const;
196 	tSharedBuffer getSprites(std::shared_ptr<cPhase> pPhase) const;
197 
missionAdd(std::shared_ptr<cMission> pMission)198 	void missionAdd(std::shared_ptr<cMission> pMission) { mMissions.push_back(pMission); }
getMissions()199     std::vector<std::shared_ptr<cMission>> getMissions() { return mMissions; }
200     std::shared_ptr<cMission> getMission(size_t pMissionNumber);
201 
202     void SetSingleMapCampaign();
203 	void SetCustomCampaign();
204 	void CreateCustomCampaign();
205 
206 	bool isCustom() const;
isCustomMap() const207     bool isCustomMap() const { return mIsCustomMap; }
setCustomMap()208     void setCustomMap() { mIsCustomMap = true; mUseCustomPath = true; }
209 
210 	bool isRandom() const;
setRandom(const bool pRandom=false)211     void setRandom(const bool pRandom = false) { mIsRandom = pRandom; }
212 
getAuthor()213     std::string getAuthor() { return mAuthor; }
setAuthor(const std::string & pAuthor)214     void setAuthor(const std::string& pAuthor) { mAuthor = pAuthor; }
215 
216 	std::string getName() const;
setName(const std::string & pName)217 	void setName(const std::string& pName) { mName = pName; }
218 
219 };
220 
221 extern const std::vector<std::string>   mMissionGoal_Titles;
222