1 /************************************************************************
2  *                                                                      *
3  *  FreeSynd - a remake of the classic Bullfrog game "Syndicate".       *
4  *                                                                      *
5  *   Copyright (C) 2005  Stuart Binge  <skbinge@gmail.com>              *
6  *   Copyright (C) 2005  Joost Peters  <joostp@users.sourceforge.net>   *
7  *   Copyright (C) 2006  Trent Waddington <qg@biodome.org>              *
8  *   Copyright (C) 2006  Tarjei Knapstad <tarjei.knapstad@gmail.com>    *
9  *   Copyright (C) 2011  Benoit Blancard <benblan@users.sourceforge.net>*
10  *   Copyright (C) 2011  Joey Parrish  <joey.parrish@gmail.com>         *
11  *                                                                      *
12  *    This program is free software;  you can redistribute it and / or  *
13  *  modify it  under the  terms of the  GNU General  Public License as  *
14  *  published by the Free Software Foundation; either version 2 of the  *
15  *  License, or (at your option) any later version.                     *
16  *                                                                      *
17  *    This program is  distributed in the hope that it will be useful,  *
18  *  but WITHOUT  ANY WARRANTY;  without even  the implied  warranty of  *
19  *  MERCHANTABILITY  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  *
20  *  General Public License for more details.                            *
21  *                                                                      *
22  *    You can view the GNU  General Public License, online, at the GNU  *
23  *  project's  web  site;  see <http://www.gnu.org/licenses/gpl.html>.  *
24  *  The full text of the license is also included in the file COPYING.  *
25  *                                                                      *
26  ************************************************************************/
27 
28 #ifndef WEAPONMANAGER_H
29 #define WEAPONMANAGER_H
30 
31 #include <vector>
32 #include <fstream>
33 
34 #include "common.h"
35 #include "weapon.h"
36 #include "utils/seqmodel.h"
37 #include "utils/portablefile.h"
38 
39 /*!
40  * Weapon manager class.
41  */
42 class WeaponManager {
43 public:
44     //! Constructor
45     WeaponManager();
46     //! Destructor
47     ~WeaponManager();
48     //! Resources destruction
49     void destroy();
50     //! Reset data
51     void reset();
52     //! Cheating mode to enable all weapons
53     void cheatEnableAllWeapons();
54     //! Enable weapon of given type
55     void enableWeapon(Weapon::WeaponType wt);
56     //! Returns the list of currently available weapons
getAvailableWeapons()57     SequenceModel * getAvailableWeapons() { return &availableWeapons_; }
58     //! Returns a weapon of given type whether it is available or not
59     Weapon *getWeapon(Weapon::WeaponType wt);
60     //! Returns true is the given weapon is available for agents
61     bool isAvailable(Weapon *pWeapon);
62 
63     //! Returns pointer if required weapon type is availiable
64     Weapon * getAvailable(Weapon::WeaponType wpn);
65     //! Creates a list of available weapons of required damage
66     void getAvailable(uint32 dmg_type, std::vector <Weapon *> &wpns);
67 
68     //! Save instance to file
69     bool saveToFile(PortableFile &file);
70     //! Load instance from file
71     bool loadFromFile(PortableFile &infile, const FormatVersion& v);
72 
73     //! checks existing weapons that can do such damage and sets whether they can shoot
74     //! strict check
75     bool checkDmgTypeCanShootStrict(uint32 dmg, bool &can_shoot);
76     //! checks existing weapons that can do such damage and sets whether they can shoot
77     //! non strict check
78     bool checkDmgTypeCanShootNonStrict(uint32 dmg, bool &can_shoot);
79 protected:
80     //! Loads the weapon from file
81     Weapon *loadWeapon(Weapon::WeaponType wt);
82 
83 protected:
84     std::vector<Weapon *> all_game_weapons_;
85     /*! This vector is used to store necessary but unavailable weapons until they
86      * are made available.*/
87     std::vector<Weapon *> preFetch_;
88     /*! This is the list of all weapons available to the user.*/
89     VectorModel<Weapon *> availableWeapons_;
90 };
91 
92 #endif
93