-
Notifications
You must be signed in to change notification settings - Fork 62
/
CWpnRest.h
115 lines (83 loc) · 2.87 KB
/
CWpnRest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/////////////////////////////////////////
//
// OpenLieroX
//
// code under LGPL, based on JasonBs work,
// enhanced by Dark Charlie and Albert Zeyer
//
//
/////////////////////////////////////////
// Weapon Restrictions class
// Created 30/3/03
// Jason Boettcher
#ifndef __CWPNREST_H__
#define __CWPNREST_H__
#include <vector>
#include <list>
#include "Iter.h"
#include "StringUtils.h" // stringcaseless
class CGameScript;
class CBytestream;
// Weapon states
enum WpnRestrictionState {
wpr_enabled = 0,
wpr_bonus = 1,
wpr_banned = 2
};
// Weapon Restriction structure
class wpnrest_t {
public:
wpnrest_t( const std::string & _name = "", WpnRestrictionState _state = wpr_enabled ):
szName(_name), state(_state) { }
std::string szName;
union {
int nState;
WpnRestrictionState state;
};
bool operator < ( const wpnrest_t & rest ) const;
};
// Weapon Restrictions class
class CWpnRest {
public:
struct WeaponName {
std::string name;
WeaponName(const std::string& n) : name(n) {}
operator std::string() const { return name; }
const char* c_str() const { return name.c_str(); }
bool operator<(const WeaponName& o) const { return stringcasecmp(name,o.name) < 0; }
bool operator==(const WeaponName& o) const { return stringcasecmp(name,o.name) == 0; }
bool operator!=(const WeaponName& o) const { return stringcasecmp(name,o.name) != 0; }
};
typedef std::map<WeaponName, WpnRestrictionState> WeaponList;
private:
// Attributes
WeaponList m_psWeaponList;
int iCycleState;
public:
// Methods
// Constructor
CWpnRest();
void loadList(const std::string& szFilename, const std::string& moddir);
void saveList(const std::string& szFilename);
void Shutdown();
void updateList(const std::vector<std::string> & weaponList);
void resetToEnabled();
void resetVisible(const std::vector<std::string> & weaponList);
void randomizeVisible(const std::vector<std::string> & weaponList);
void cycleVisible(const std::vector<std::string> & weaponList);
void sendList(CBytestream *psByteS, const std::vector<std::string> & weaponList);
void readList(CBytestream *psByteS);
bool isEnabled(const std::string& szName);
bool isBonus(const std::string& szName);
std::string findEnabledWeapon(const std::vector<std::string> & weaponList);
int getWeaponState(const std::string& szName);
Iterator<wpnrest_t>::Ref getList();
WpnRestrictionState *findWeapon(const std::string& szName);
void setWeaponState(const std::string& szName, WpnRestrictionState nState);
int getNumWeapons() const;
static bool weaponExists(const std::string & weapon, const std::vector<std::string> & weaponList);
private:
// Internal methods
void addWeapon(const std::string& szName, int nState);
};
#endif // __CWPNREST_H__