forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_party.h
486 lines (405 loc) · 9.99 KB
/
game_party.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EP_GAME_PARTY_H
#define EP_GAME_PARTY_H
// Headers
#include <cstdint>
#include <vector>
#include "game_party_base.h"
#include "game_actor.h"
#include <lcf/rpg/saveinventory.h>
/**
* Game_Party class.
*/
class Game_Party : public Game_Party_Base {
public:
/**
* Initializes Game_Party.
*/
Game_Party();
/** Initialize for new game */
void SetupNewGame();
/** Setups battle test party */
void SetupBattleTest();
/** Initialize from save game */
void SetupFromSave(lcf::rpg::SaveInventory save);
/** @return save game data */
const lcf::rpg::SaveInventory& GetSaveData() const;
Game_Actor& operator[] (const int index) override;
int GetBattlerCount() const override;
int GetVisibleBattlerCount() const override;
/**
* Adds an actor to the party.
*
* @param actor_id database actor ID.
*/
void AddActor(int actor_id);
/**
* Removes an actor from the party.
*
* @param actor_id database actor ID.
*/
void RemoveActor(int actor_id);
/**
* Removes all actors from the party.
*/
void Clear();
/**
* Gets if an actor is in party.
*
* @param actor_id database actor ID.
* @return whether the actor is in party.
*/
bool IsActorInParty(int actor_id);
/**
* Gets position of actor in party.
*
* @param actor_id database actor ID
* @return Party position 0 - 3 or -1 if not in
*/
int GetActorPositionInParty(int actor_id);
/**
* Gains gold.
*
* @param value gained gold.
*/
void GainGold(int value);
/**
* Loses gold.
*
* @param value lost gold.
*/
void LoseGold(int value);
/**
* Returns all items of the party sorted by item id.
*
* @param item_list vector to fill.
*/
void GetItems(std::vector<int>& item_list);
/**
* Gets number of item in inventory.
*
* @param item_id database item ID.
* @return number of items.
*/
int GetItemCount(int item_id) const;
/**
* Gets number of item equipped by the party.
*
* @param item_id database item ID.
* @return number of items.
*/
int GetEquippedItemCount(int item_id) const;
/**
* Gets number of item in inventory and equipped by party.
*
* @param item_id database item ID.
* @return number of items.
*/
int GetItemTotalCount(int item_id) const;
/**
* Gets maximum number of item allowed in inventory.
*
* @param item_id database item ID.
* @return maximum number of items.
*/
int GetMaxItemCount(int item_id) const;
/**
* Gains an amount of items.
*
* @param item_id database item ID.
* @param amount gained quantity.
*/
void AddItem(int item_id, int amount);
/**
* Loses an amount of items.
*
* @param item_id database item ID.
* @param amount lost quantity.
*/
void RemoveItem(int item_id, int amount);
/**
* Consumes one use of an item (eg. for multi-use items).
* Doesn't actually do anything with the item, just uses up one use.
*
* @param item_id database item ID
*/
void ConsumeItemUse(int item_id);
/**
* Gets if item can be used.
* When a target is specified this also checks if the target can use the item.
*
* @param item_id database item ID.
* @param target Target to test
* @return whether the item can be used.
*/
bool IsItemUsable(int item_id, const Game_Actor* target = nullptr) const;
/**
* Uses an item on an actor.
* Tests if using that item makes any sense (e.g. for HP healing
* items if there are any HP to heal)
*
* @param item_id ID of item to use
* @param target Target the item is used on (or NULL if its for the party)
*/
bool UseItem(int item_id, Game_Actor* target = nullptr);
/**
* Determines if a skill can be used.
* When a target is specified this also checks if the target can use the item.
*
* @param skill_id Skill to test
* @param target Skill user to test
* @param from_item Skill is invoked by an item. This alters the usable check outside of battles.
*/
bool IsSkillUsable(int skill_id, const Game_Actor* target = nullptr, bool from_item = false) const;
/**
* Uses a skill on an actor.
* Tests if using that skill makes any sense (e.g. for HP healing
* skills if there are any HP to heal)
*
* @param skill_id ID of skill to use
* @param source Actor using the skill
* @param target Target the skill is used on (or NULL if its for the party)
*/
bool UseSkill(int skill_id, Game_Actor* source, Game_Actor* target = NULL);
/**
* Gets gold possessed.
*
* @return gold possessed.
*/
int GetGold() const;
/**
* Gets steps walked.
*
* @return steps walked.
*/
int GetSteps() const;
/**
* Increment the number of steps walked by 1.
*/
void IncSteps();
/**
* Gets actors in party list.
*
* @return actors in party list.
*/
std::vector<Game_Actor*> GetActors() const;
/**
* Get's the i'th actor in the party.
*
* @param idx the party index starting from 0.
*
* @return actor at index, or nullptr if no such actor
*/
Game_Actor* GetActor(int idx) const;
/**
* Gets number of battles.
*
* @return number of battles.
*/
int GetBattleCount() const;
/**
* Increment the number of battles by 1.
*/
void IncBattleCount();
/**
* Gets number of battles wins.
*
* @return number of battles wins.
*/
int GetWinCount() const;
/**
* Increment the number of battles wins by 1.
*/
void IncWinCount();
/**
* Gets number of battles defeats.
*
* @return number of battles defeats.
*/
int GetDefeatCount() const;
/**
* Increment the number of battles defeats by 1.
*/
void IncDefeatCount();
/**
* Gets number of battles escapes.
*
* @return number of battles escapes.
*/
int GetRunCount() const;
/**
* Increment the number of battles escapes by 1.
*/
void IncRunCount();
/**
* Damages all actors in party by the same value.
* Used by damage terrain on the map.
*
* @param damage How many damage to apply
* @param lethal If the damage can be lethal (kill a character) or not
*/
void ApplyDamage(int damage, bool lethal);
/**
* Gets average level of the party (for battle)
*
* @return average level
*/
int GetAverageLevel();
/**
* Gets party exhaustion level (for battle)
*
* @return exhaustion level
*/
int GetFatigue();
enum sys_timer {
Timer1,
Timer2
};
/**
* Sets a timer.
*
* @param which which timer to set.
* @param seconds the time in seconds.
*/
void SetTimer(int which, int seconds);
/**
* Starts a timer.
*
* @param which which timer to start.
* @param visible whether the timer is visible.
* @param battle whether the timer runs during battle.
*/
void StartTimer(int which, bool visible, bool battle);
/**
* Stops a timer.
*
* @param which which timer to stop.
*/
void StopTimer(int which);
/**
* Updates all timers.
*/
void UpdateTimers();
/**
* Get a timer's value in seconds.
*
* @param which which timer to read.
* @return number of seconds remaining.
*/
int GetTimerSeconds(int which);
/**
* Get a timer's value in frames.
*
* @param which which timer to read.
* @return number of frames remaining.
*/
int GetTimerFrames(int which);
/**
* Returns whether a timer should be visible now
*
* @param which which timer to read
* @param in_battle whether we're currently in a battle.
*
* @return true if visible.
*/
bool GetTimerVisible(int which, bool in_battle);
/**
* Removes invalid actors and items from the party
*/
void RemoveInvalidData();
std::vector<int16_t> GetInflictedStates() const;
/**
* Applies damage to the game party based on their stats.
*
* @return Whether the actor suffered some damage.
*/
bool ApplyStateDamage();
/**
* @return Whether any party member accepts custom battle commands.
*/
bool IsAnyControllable();
/**
* Gets the actor with the highest level who can act and use the given item. If there are many, choose the one with the earliest position in the group.
*
* @param the item to check
*
* @return The first Highest leveled actor who can act.
*/
Game_Actor* GetHighestLeveledActorWhoCanUse(const lcf::rpg::Item*) const;
/**
* If a battle is running, returns the current battle turn for the party.
* Otherwise, returns the number of turns of the last battle
*
* @return number of turns
*/
int GetTurns() const;
/** Increment turn counter */
void IncTurns();
/** Reset turn counter to 0 */
void ResetTurns();
private:
std::pair<int,bool> GetItemIndex(int item_id) const;
lcf::rpg::SaveInventory data;
};
// ------ INLINES --------
inline const lcf::rpg::SaveInventory& Game_Party::GetSaveData() const {
return data;
}
inline int Game_Party::GetBattleCount() const {
return data.battles;
}
inline void Game_Party::IncBattleCount() {
++data.battles;
}
inline int Game_Party::GetWinCount() const {
return data.victories;
}
inline void Game_Party::IncWinCount() {
++data.victories;
}
inline int Game_Party::GetDefeatCount() const {
return data.defeats;
}
inline void Game_Party::IncDefeatCount() {
++data.defeats;
}
inline int Game_Party::GetRunCount() const {
return data.escapes;
}
inline void Game_Party::IncRunCount() {
++data.escapes;
}
inline int Game_Party::GetGold() const {
return data.gold;
}
inline int Game_Party::GetSteps() const {
return data.steps;
}
inline void Game_Party::IncSteps() {
++data.steps;
}
inline int Game_Party::GetTurns() const {
return data.turns;
}
inline void Game_Party::IncTurns() {
++data.turns;
}
inline void Game_Party::ResetTurns() {
data.turns = 0;
}
#endif