1 /*
2 * This file is part of GtkEveMon.
3 *
4 * GtkEveMon 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 3 of the License, or
7 * (at your option) any later version.
8 *
9 * You should have received a copy of the GNU General Public License
10 * along with GtkEveMon. If not, see <http://www.gnu.org/licenses/>.
11 */
12
13 #ifndef API_CHAR_SHEET_HEADER
14 #define API_CHAR_SHEET_HEADER
15
16 #include <string>
17 #include <vector>
18 #include <libxml/parser.h>
19
20 #include "util/ref_ptr.h"
21 #include "net/http.h"
22 #include "apibase.h"
23 #include "apiskilltree.h"
24 #include "apicerttree.h"
25
26 /* The minimum amount of seconds the sheet is cached. */
27 #define API_CHAR_SHEET_MIN_CACHE_TIME 1800
28
29 struct ApiCharSheetSkill
30 {
31 int id;
32 int level;
33 int points;
34 int points_max;
35 int points_start;
36 int points_dest;
37 double completed;
38 ApiSkill const* details;
39 };
40
41 /* ---------------------------------------------------------------- */
42
43 struct ApiCharSheetCert
44 {
45 int id;
46 ApiCert const* details;
47 };
48
49 /* ---------------------------------------------------------------- */
50
51 struct ApiCharAttribs
52 {
53 double intl;
54 double mem;
55 double cha;
56 double per;
57 double wil;
58
59 ApiCharAttribs (void);
60 ApiCharAttribs (double value);
61
62 ApiCharAttribs operator+ (ApiCharAttribs const& atts) const;
63 ApiCharAttribs operator+ (double const& value) const;
64 ApiCharAttribs& operator+= (ApiCharAttribs const& atts);
65
66 ApiCharAttribs operator- (ApiCharAttribs const& atts) const;
67 ApiCharAttribs operator- (double const& value) const;
68 ApiCharAttribs& operator-= (ApiCharAttribs const& atts);
69
70 ApiCharAttribs operator* (ApiCharAttribs const& atts) const;
71 ApiCharAttribs operator* (double const& value) const;
72
73 ApiCharAttribs operator/ (ApiCharAttribs const& atts) const;
74 ApiCharAttribs operator/ (double const& value) const;
75
76 ApiCharAttribs& operator= (double const& value);
77 };
78
79 /* ---------------------------------------------------------------- */
80
81 class ApiCharSheet;
82 typedef ref_ptr<ApiCharSheet> ApiCharSheetPtr;
83
84 class ApiCharSheet : public ApiBase
85 {
86 /* Some internal stuff. */
87 protected:
88 ApiCharSheet (void);
89
90 void parse_xml (void);
91 void parse_eveapi_tag (xmlNodePtr node);
92 void parse_result_tag (xmlNodePtr node);
93 void parse_attribute_tag (xmlNodePtr node);
94 void parse_attrib_enhancers_tag (xmlNodePtr node);
95 void parse_skills_tag (xmlNodePtr node);
96 void parse_certificates_tag (xmlNodePtr node);
97
98 void find_implant_bonus (xmlNodePtr node, char const* name, double& var);
99 void debug_dump (void);
100
101 /* Publicly available collection of gathered data. */
102 public:
103 bool valid;
104
105 /* Basic char information. */
106 std::string char_id;
107 std::string name;
108 std::string race;
109 std::string bloodline;
110 std::string gender;
111 std::string corp;
112 std::string balance;
113
114 /* Clone and respec info. */
115 std::string clone_name;
116 unsigned int clone_sp;
117 unsigned int free_sp;
118 std::string last_respec;
119 std::string last_timed_respec;
120 unsigned int free_respecs;
121 std::string last_clone_jump;
122
123 /* Attribute values for the character. */
124 ApiCharAttribs base;
125 ApiCharAttribs implant;
126 ApiCharAttribs total;
127
128 /* The vector of all known skills and certs. */
129 std::vector<ApiCharSheetSkill> skills;
130 std::vector<ApiCharSheetCert> certs;
131
132 /* Statistics. */
133 unsigned int total_sp;
134 unsigned int skills_at[6];
135
136 public:
137 static ApiCharSheetPtr create (void);
138 void set_api_data (EveApiData const& data);
139
140 /* Check whether the character knows this skill */
141 bool is_skill_known (int id);
142
143 /* Lookup methods for skills. This is expensive. */
144 ApiCharSheetSkill* get_skill_for_id (int id);
145 int get_level_for_skill (int id) const;
146
147 /* Lookup methods for certificates. This is expensive. */
148 ApiCharSheetCert* get_cert_for_id (int id);
149 int get_grade_for_class (int class_id) const;
150
151 /* Adds a new skill to the character if it's not already
152 * present. Statistics are appropriately updated. */
153 void add_char_skill (int skill_id, int level);
154
155 /* Calculates the SP/h for the given skill based on the
156 * character total attributes or the specified attributes. */
157 unsigned int get_spph_for_skill (ApiSkill const* skill);
158 unsigned int get_spph_for_skill (ApiSkill const* skill,
159 ApiCharAttribs const& attribs);
160
161 /* Generic calculation of skill start and destination SP.
162 * This is character independent. */
163 static int calc_start_sp (int level, int rank);
164 static int calc_dest_sp (int level, int rank);
165 };
166
167 /* ---------------------------------------------------------------- */
168
169 inline
ApiCharAttribs(void)170 ApiCharAttribs::ApiCharAttribs (void)
171 {
172 }
173
174 inline
ApiCharAttribs(double value)175 ApiCharAttribs::ApiCharAttribs (double value)
176 {
177 this->intl = value;
178 this->mem = value;
179 this->cha = value;
180 this->per = value;
181 this->wil = value;
182 }
183
184 inline
ApiCharSheet(void)185 ApiCharSheet::ApiCharSheet (void) : valid(false)
186 {
187 }
188
189 inline ApiCharSheetPtr
create(void)190 ApiCharSheet::create (void)
191 {
192 return ApiCharSheetPtr(new ApiCharSheet);
193 }
194
195 inline unsigned int
get_spph_for_skill(ApiSkill const * skill)196 ApiCharSheet::get_spph_for_skill (ApiSkill const* skill)
197 {
198 return this->get_spph_for_skill(skill, this->total);
199 }
200
201 #endif /* API_CHAR_SHEET_HEADER */
202