forked from tanglewoodforest/src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfood.cc
More file actions
378 lines (313 loc) · 9.05 KB
/
food.cc
File metadata and controls
378 lines (313 loc) · 9.05 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
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
#include <ctype.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include "define.h"
#include "struct.h"
const char* cook_word [] = { "none", "raw", "cooked", "burnt" };
const default_data consume_msg [] =
{
{ "to_char", "You eat $q.", -1 },
{ "to_char", "You eat part of $q.", -1 },
{ "to_char", "You rip $q into shreds and happily munch on it. Who said real trolls don't eat salad?", ITEM_SCROLL },
{ "to_char", "You gleefully pull apart $q and eat it piece by piece.", ITEM_CORPSE },
{ "to_char", "You pull a tender piece off $q and eat it.", ITEM_CORPSE },
{ "to_room", "$n eats $q.", -1 },
{ "to_room", "$n eats part of $q.", -1 },
{ "to_room", "$n rips $q into shreds and happily munches on it.", ITEM_SCROLL },
{ "to_room", "$n pulls apart $q and eats it piece by piece, making a disgusting sight.", ITEM_CORPSE },
{ "to_room", "$n pulls a tender piece off $q and eats it.", ITEM_CORPSE },
{ "", "", -1 }
};
/*
* EAT ROUTINES
*/
static bool eats_corpses( char_data* ch )
{
if( ch->species
&& is_set( ch->species->act_flags, ACT_CARNIVORE ) )
return true;
return( ch->shdata->race == RACE_TROLL
|| ch->shdata->race == RACE_ORC );
}
bool vegetarian( char_data* ch )
{
if( ch->species
&& !is_set( ch->species->act_flags, ACT_CARNIVORE ) )
return true;
return( ch->shdata->race == RACE_ENT );
}
bool carnivore( char_data* ch )
{
if( ch->species )
return ch->shdata->race == RACE_UNDEAD;
return( ch->shdata->race == RACE_ORC );
}
bool can_eat( char_data* ch, obj_data* obj, bool msg )
{
if( obj->array == ch->array
&& ch->mount ) {
if( msg ) {
send( ch, "Unless you dismount, you can only eat things you are carrying.\n\r" );
}
return false;
}
if( !can_wear( obj, ITEM_TAKE ) ) {
if( msg )
fsend( ch, "You cannot eat %s.", obj );
return false;
}
if( obj->pIndexData->item_type == ITEM_CORPSE ) {
if( !eats_corpses( ch ) ) {
if( msg )
send( ch, "What a disgusting suggestion!\n\r" );
return false;
}
if( obj != forbidden( obj, ch ) ) {
if( msg )
fsend( ch,
"You feel the gods would be unduly displeased if you ate %s.",
obj );
return false;
}
} else if( obj->pIndexData->item_type != ITEM_FOOD ) {
if( ch->shdata->race == RACE_TROLL ) {
if( obj->any_metal( ) || obj->stone( ) ) {
if( msg )
send( ch, "That is a bit too crunchy even for your taste.\n\r" );
return false;
}
} else {
if( msg )
send( ch, "That's not edible.\n\r" );
return false;
}
}
if( is_set( obj->extra_flags, OFLAG_FLAMING )
|| is_set( obj->extra_flags, OFLAG_BURNING ) ) {
if( msg )
fsend( ch, "If you feel the need for a good burn, eat a habanero pepper instead of %s.", obj );
return false;
}
if( is_set( obj->extra_flags, OFLAG_DIVINE ) ) {
if( msg )
fsend( ch,
"You feel the gods would be unduly displeased if you ate %s.",
obj );
return false;
}
if( vegetarian( ch )
&& is_set( obj->materials, MAT_FLESH ) ) {
if( msg )
send( ch, "You do not find meat edible.\n\r" );
return false;
}
if( carnivore( ch )
&& !is_set( obj->materials, MAT_FLESH )
&& obj->pIndexData->item_type != ITEM_CORPSE ) {
if( msg )
send( ch, "You only eat flesh.\n\r" );
return false;
}
if( ch->condition[COND_FULL] > 40
&& !privileged( ch, LEVEL_DEMIGOD ) ) {
if( msg ) {
send( ch, "You are too full to eat more.\n\r" );
if( is_set( ch->status, STAT_ORDERED ) ) {
interpret( ch, "shake" );
}
}
return false;
}
if( obj->pIndexData->item_type != ITEM_CORPSE
&& !obj->contents.is_empty() ) {
if( msg )
send( ch, "That object is not empty, remove its contents first.\n\r" );
return false;
}
return true;
}
bool eat( char_data* ch, obj_data* obj )
{
ch->Select( 1 );
if( !can_eat( ch, obj, true ) )
return false;
int to_char;
int to_room;
if( obj->pIndexData->item_type == ITEM_SCROLL ) {
to_char = 2;
to_room = 7;
} else if( obj->pIndexData->item_type == ITEM_CORPSE ) {
to_char = 3;
to_room = 8;
} else {
to_char = 0;
to_room = 5;
}
int food_value = obj->pIndexData->item_type != ITEM_FOOD
? obj->weight/100
: obj->value[0];
oprog_data *oprog;
for( oprog = obj->pIndexData->oprog; oprog; oprog = oprog->next ) {
if( oprog->trigger == OPROG_TRIGGER_CONSUME ) {
obj->Select( 1 );
push( );
clear_variables( );
var_ch = ch;
var_obj = obj;
var_room = ch->in_room;
var_def = consume_msg;
var_def_type = -1;
const int result = oprog->execute( );
pop( );
if( !result )
return true;
// if( !obj->Is_Valid( ) )
// return false;
break;
}
}
bool limited = false;
int limit = food_value;
if( obj->Is_Valid( ) ) {
if( !oprog
&& !privileged( ch, LEVEL_DEMIGOD )
&& ( obj->pIndexData->item_type == ITEM_FOOD
|| obj->pIndexData->item_type == ITEM_CORPSE ) ) {
limit = min( 50-ch->condition[COND_FULL], food_value );
if( limit < food_value ) {
// Can't eat it all. Take home leftovers.
++to_char;
++to_room;
limited = true;
}
}
act( ch, prog_msg( oprog, consume_msg[to_char] ), 0, 0, obj );
act_seen( prog_msg( oprog, consume_msg[to_room] ), ch, 0, obj );
}
if( obj->pIndexData->item_type == ITEM_FOOD ) {
if( is_set( obj->value[3], CONSUME_POISON )
&& poison( ch, 5, 2 * obj->value[0], true ) ) {
food_value /= 2;
}
if( is_set( obj->value[3], CONSUME_PLAGUE )
&& plague( ch, number_range( 5, 12 ), true ) ) {
food_value /= 3;
}
if ( obj->value[1] == COOK_RAW
|| obj->value[1] == COOK_BURNT ) {
food_value /= 2;
}
limit = min( food_value, limit );
}
gain_condition( ch, COND_FULL, food_value );
if( obj->Is_Valid( ) ) {
if( limited ) {
Content_Array *where = obj->array;
// Eat only part.
obj = (obj_data*)obj->From(1);
if( obj->pIndexData->item_type == ITEM_FOOD ) {
obj->value[0] -= limit;
if( obj->pIndexData->vnum == OBJ_BODY_PART ) {
obj->weight = obj->weight * ( obj->value[0] - limit ) / obj->value[0];
obj->weight = max( obj->weight, 1 );
} else {
obj->weight = obj->value[0]*obj->pIndexData->weight/obj->pIndexData->value[0];
}
} else {
obj->weight -= 100*limit;
}
if( obj->pIndexData->weight > 0 ) {
obj->weight = max( 1, obj->weight );
}
obj->To( *where );
} else if( obj->pIndexData->item_type == ITEM_CORPSE ) {
extract_corpse( obj );
} else {
obj->Extract( 1 );
}
}
return true;
}
void do_eat( char_data* ch, const char *argument )
{
if( ch->fighting ) {
send( ch, "Eating during combat would be hazardous to your health.\n\r" );
return;
}
obj_data* obj;
if( !( obj = one_object( ch, argument, "eat",
&ch->contents,
ch->array ) ) )
return;
if( eat( ch, obj ) )
set_delay( ch, 10 );
}
/*
* COOK ROUTINES
*/
void do_cook( char_data* ch, const char *argument )
{
if( is_fighting( ch, "cook" ) )
return;
if( !*argument ) {
send( ch, "What do you wish to cook?\n\r" );
return;
}
obj_data *obj;
if( !( obj = one_object( ch, argument, "cook", &ch->contents ) ) ) {
return;
}
obj_data *fire;
if( !( fire = find_type( ch, *ch->array, ITEM_FIRE ) ) ) {
send( ch, "You see nothing here on which to cook.\n\r", obj );
return;
}
if( obj->pIndexData->item_type != ITEM_FOOD
|| obj->value[1] < COOK_RAW
|| obj->value[1] > COOK_BURNT ) {
send( ch, "You don't see what good cooking %s will do.\n\r", obj );
return;
}
fsend( ch, "You cook %s over %s.", obj, fire );
fsend_seen( ch, "%s cooks %s over %s.", ch, obj, fire );
set_delay( ch, 15 );
if ( obj->value[1] == COOK_BURNT ) {
fsend( ch, "%s is reduced to inedible ashes.", obj );
fsend_seen( ch, "%s is reduced to inedible ashes.", obj );
obj->Extract(1);
return;
}
int new_val = obj->value[1]+1;
if ( !ch->check_skill( TRADE_COOKING ) ) {
if ( new_val == COOK_COOKED ) {
if ( number_range( 1, 4 ) > 1 ) {
new_val = COOK_BURNT;
} else {
send( ch, "Despite your best efforts, your food remains raw.\n\r" );
fsend_seen( ch, "Oddly, %s efforts don't make %s any more palatable.",
ch->His_Her(), obj );
return;
}
}
}
if ( new_val == COOK_BURNT ) {
fsend( ch, "%s is transformed into a blackened, smoking lump.", obj );
fsend_seen( ch, "%s is transformed into a blackened, smoking lump.", obj );
}
obj = (obj_data *)obj->From( 1, true );
obj->value[1] = new_val;
// Cooked food is less likely to be poisonous or diseased.
if( is_set( obj->value[3], CONSUME_POISON )
&& number_range( 1, 4 ) == 1 ) {
remove_bit( obj->value[3], CONSUME_POISON );
}
if( is_set( obj->value[3], CONSUME_PLAGUE )
&& number_range( 1, 4 ) == 1 ) {
remove_bit( obj->value[3], CONSUME_PLAGUE );
}
obj->To( 0 );
if ( new_val == COOK_COOKED ) {
ch->improve_skill( TRADE_COOKING );
}
}