forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
npctrade.h
102 lines (85 loc) · 2.84 KB
/
npctrade.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
#pragma once
#ifndef CATA_SRC_NPCTRADE_H
#define CATA_SRC_NPCTRADE_H
#include <cstddef>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <list>
#include "inventory.h"
#include "item_location.h"
#include "output.h"
#include "units.h"
#include "cursesdef.h"
#include "translations.h"
class Character;
class faction;
class item;
class npc;
class player;
class ui_adaptor;
class item_pricing
{
public:
item_pricing( Character &c, item &it, int v, int count ) : loc( c, &it ), price( v ) {
set_values( count );
}
item_pricing( item_location &&l, int v, int count ) : loc( std::move( l ) ), price( v ) {
set_values( count );
}
void set_values( int ip_count );
void adjust_values( double adjust, const faction *fac );
item_location loc;
int price;
// Whether this is selected for trading
bool selected = false;
bool is_container;
int count = 0;
int charges = 0;
int u_has = 0;
int npc_has = 0;
int u_charges = 0;
int npc_charges = 0;
units::mass weight = 0_gram;
units::volume vol = 0_ml;
};
class trading_window
{
public:
trading_window() = default;
std::vector<item_pricing> theirs;
std::vector<item_pricing> yours;
int your_balance = 0;
void setup_trade( int cost, npc &np );
bool perform_trade( npc &np, const std::string &deal );
void update_npc_owed( npc &np );
private:
void setup_win( ui_adaptor &ui );
void update_win( npc &np, const std::string &deal );
void show_item_data( size_t offset, std::vector<item_pricing> &target_list );
catacurses::window w_head;
catacurses::window w_them;
catacurses::window w_you;
size_t entries_per_page = 0;
bool focus_them = true; // Is the focus on them?
size_t them_off = 0, you_off = 0; // Offset from the start of the list
inventory temp;
units::volume volume_left;
units::mass weight_left;
int get_var_trade( const item &it, int total_count, int amount_hint );
bool npc_will_accept_trade( const npc &np ) const;
int calc_npc_owes_you( const npc &np ) const;
};
namespace npc_trading
{
bool pay_npc( npc &np, int cost );
int cash_to_favor( const npc &, int cash );
void transfer_items( std::vector<item_pricing> &stuff, player &giver, player &receiver,
std::list<item_location *> &from_map, bool npc_gives );
double net_price_adjustment( const player &buyer, const player &seller );
bool trade( npc &p, int cost, const std::string &deal );
std::vector<item_pricing> init_selling( npc &p );
std::vector<item_pricing> init_buying( player &buyer, player &seller, bool is_npc );
} // namespace npc_trading
#endif // CATA_SRC_NPCTRADE_H