forked from tanglewoodforest/src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank.cc
More file actions
296 lines (225 loc) · 6.95 KB
/
bank.cc
File metadata and controls
296 lines (225 loc) · 6.95 KB
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
#include <ctype.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include "define.h"
#include "struct.h"
static bool in_bank ( char_data* );
obj_data* obj_from_locker ( obj_data*, char_data*, int );
/*
* BANK FUNCTIONS
*/
bool in_bank( char_data* ch )
{
if( is_mob( ch ) )
return false;
if( !ch->Can_See( true ) )
return false;
room_data *room;
if( !( room = Room( ch->array->where ) )
|| !is_set( room->room_flags, RFLAG_BANK ) ) {
send( ch, "You are not in a banking institution.\n\r" );
return false;
}
return true;
}
void do_balance( char_data* ch, const char *argument )
{
player_data *pc;
bool loaded = false;
if( has_permission( ch, PERM_PLAYERS )
&& *argument ) {
in_character = false;
char arg [ MAX_INPUT_LENGTH ];
argument = one_argument( argument, arg );
pfile_data *pfile = find_pfile( arg, ch );
if( !pfile )
return;
if( pfile != ch->pcdata->pfile
&& pfile->trust >= get_trust( ch ) ) {
fsend( ch, "You cannot view the bank account of %s.", pfile->name );
return;
}
if( !( pc = find_player( pfile ) ) ) {
link_data link;
link.connected = CON_PLAYING;
if( !load_char( &link, pfile->name, PLAYER_DIR ) ) {
bug( "Load_players: error reading player file. (%s)", pfile->name );
return;
}
pc = link.player;
loaded = true;
}
if( *argument ) {
if( ch != pc ) {
snprintf( arg, MAX_INPUT_LENGTH, "Bank account for %s", pc->Name( ch ) );
}
browse( ch, argument, &pc->locker, ( ch == pc ) ? 0 : arg );
if( loaded ) {
page( ch, "\n\r" );
page_centered( ch, "[ Player file was loaded from disk. ]" );
pc->Extract();
extracted.delete_list();
}
return;
}
} else {
if( !in_bank( ch ) )
return;
pc = player( ch );
}
bool same = ( ch == pc );
if( pc->locker.is_empty() ) {
if( pc->bank == 0 ) {
fpage( ch, "%s %s no items or coins stored with the bank.",
same ? "You" : pc->Name( ch ),
same ? "have" : "has" );
} else {
fpage( ch,
"%s %s %d copper coin%s, but no items stored with the bank.",
same ? "You" : pc->Name( ch ),
same ? "have" : "has",
pc->bank, pc->bank == 1 ? "" : "s" );
}
} else {
select( pc->locker );
rehash_weight( ch, pc->locker );
if( !same ) {
page_title( ch, "Bank account for %s", pc );
}
page( ch, "Copper Coins: %d\n\r", pc->bank );
page( ch, "Total Weight: %.2f lbs\n\r\n\r",
0.01*(double)pc->locker.weight );
page_underlined( ch,
"Items in Storage Weight\n\r" );
for( int i = 0; i < pc->locker; i++ ) {
obj_data *obj = (obj_data*) pc->locker[i];
if( obj->Shown( ) > 0 ) {
page( ch, "%-70s %7.2f\n\r",
obj->Seen_Name( ch, obj->Shown( ), true ),
0.01*(double)obj->temp );
}
}
}
if( loaded ) {
page( ch, "\n\r" );
page_centered( ch, "[ Player file was loaded from disk. ]" );
pc->Extract();
extracted.delete_list();
}
}
/*
* DEPOSIT
*/
thing_data* deposit( thing_data* thing, char_data* ch, thing_data* )
{
obj_data *obj = (obj_data*) thing->From( thing->Selected( ) );
player_data *pc = (player_data*) ch;
if( obj->pIndexData->item_type != ITEM_MONEY ) {
obj->To( pc->locker );
} else {
pc->bank += monetary_value( obj );
obj->Extract( );
}
return obj;
}
void do_deposit( char_data* ch, const char *argument )
{
if( !in_bank( ch ) )
return;
player_data *pc = player( ch );
if( !*argument ) {
send( ch, "What do you want to deposit?\n\r" );
return;
}
int amount;
if( number_arg( argument, amount ) ) {
if( amount <= 0 ) {
send( ch, "You may only deposit positive amounts.\n\r" );
} else if( !remove_coins( ch, amount, "You deposit" ) ) {
send( ch, "You don't have that much to deposit.\n\r" );
} else {
pc->bank += amount;
send( ch, "You now have %d cp in your account.\n\r", pc->bank );
}
return;
}
thing_array *array;
if( !( array = several_things( ch, argument, "deposit", &ch->contents ) ) )
return;
const bool empty = pc->bank == 0 && pc->locker.is_empty( );
thing_array subset [ 6 ];
thing_func* func [ 6 ] = { cursed, stolen, stolen_contents,
corpse, no_room, deposit };
sort_objects( ch, *array, 0, 6, subset, func );
msg_type = MSG_BANK;
page_priv( ch, 0, empty_string );
page_priv( ch, &subset[0], "can't let go of" );
page_priv( ch, &subset[1], "don't own" );
page_priv( ch, &subset[2], "don't own something in" );
page_priv( ch, &subset[3], 0, 0, "is refused", "are refused" );
page_priv( ch, &subset[4], "don't have space for" );
if( !subset[5].is_empty() && empty ) {
page( ch, "You open a bank account.\n\r" );
}
page_publ( ch, &subset[5], "deposit" );
delete array;
}
/*
* WITHDRAW
*/
static const char *const auction_msg = "That would take your bank balance below what\
you have bid on the\n\rauction block and if you did that the delivery daemons would rip you apart\n\rand play catch with the pieces.\n\r";
void do_withdraw( char_data* ch, const char *argument )
{
if( !in_bank( ch ) )
return;
player_data *pc = player( ch );
if( !*argument ) {
send( ch, "What do you want to withdraw?\n\r" );
return;
}
int amount;
// Use isdigit() so +1, -1, etc. are keywords, not amounts.
// (For +1 weapon/armor, etc.)
if( isdigit( *argument ) && number_arg( argument, amount ) ) {
if( amount == 0 ) {
send( ch, "Your balance is %d copper coins.\n\r", pc->bank );
send( ch, "How much do you wish to withdraw?\n\r" );
return;
} else if( amount < 0 ) {
send( ch, "Number out of range.\n\rTry a smaller amount.\n\r" );
return;
} if( amount > pc->bank ) {
send( ch, "That is more than you have in your account.\n\r" );
} else if( amount > free_balance( pc ) ) {
send( ch, auction_msg );
} else {
add_coins( ch, amount, "The bank teller hands you" );
fsend_seen( ch, "%s withdraws some money.", ch );
pc->bank -= amount;
if( pc->bank == 0 && pc->locker.is_empty( ) ) {
page( ch, "You close your bank account.\n\r" );
} else {
send( ch, "Your remaining balance is %d copper coins.\n\r", pc->bank );
}
}
return;
}
thing_array *array;
if( !( array = several_things( ch, argument, "withdraw", &pc->locker ) ) )
return;
/* HANDLE ITEM LIST */
thing_array subset [ 3 ];
thing_func* func [ 3 ] = { heavy, many, to_char };
sort_objects( ch, *array, 0, 3, subset, func );
msg_type = MSG_BANK;
page_priv( ch, 0, empty_string );
page_priv( ch, &subset[0], "can't lift" );
page_priv( ch, &subset[1], "can't handle" );
page_publ( ch, &subset[2], "withdraw" );
if( pc->bank == 0 && pc->locker.is_empty( ) ) {
page( ch, "You close your bank account.\n\r" );
}
delete array;
}