Crossfire Server, Trunk
lighter.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
18 #include "global.h"
19 
20 #include <string.h>
21 
22 #include "ob_methods.h"
23 #include "ob_types.h"
24 #include "sounds.h"
25 #include "sproto.h"
26 
27 static method_ret lighter_type_apply(object *lighter, object *applier, int aflags);
28 
32 void init_type_lighter(void) {
34 }
35 
52 static method_ret lighter_type_apply(object *lighter, object *applier, int aflags) {
53  object *item;
54  (void)aflags;
55 
56  if (applier->type != PLAYER)
57  return METHOD_UNHANDLED;
58 
59  item = find_marked_object(applier);
60  if (!item) {
62  "You need to mark a lightable object.");
63  return METHOD_OK;
64  }
65 
66  if (lighter->last_eat && lighter->stats.food) {
67  /* Split multiple lighters if they're being used up. Otherwise
68  * one charge from each would be used up. --DAMN
69  */
70  if (lighter->nrof > 1) {
71  object *oneLighter = object_split(lighter, 1, NULL, 0);
72 
73  oneLighter->stats.food--;
74  oneLighter = object_insert_in_ob(oneLighter, applier);
75  } else {
76  lighter->stats.food--;
77  }
78  } else if (lighter->last_eat) { /* no charges left in lighter */
80  "You fail to light the %s with a used up %s.",
81  item->name, lighter->name);
82  return METHOD_OK;
83  }
84 
85  do_light(item, lighter->name, applier);
86 
87  return METHOD_OK;
88 }
PLAYER
@ PLAYER
Definition: object.h:110
global.h
init_type_lighter
void init_type_lighter(void)
Definition: lighter.cpp:32
register_apply
void register_apply(int ob_type, apply_func method)
Definition: ob_types.cpp:62
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
draw_ext_info_format
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
lighter_type_apply
static method_ret lighter_type_apply(object *lighter, object *applier, int aflags)
Definition: lighter.cpp:52
object_insert_in_ob
object * object_insert_in_ob(object *op, object *where)
Definition: object.cpp:2851
obj::nrof
uint32_t nrof
Definition: object.h:340
METHOD_UNHANDLED
#define METHOD_UNHANDLED
Definition: ob_methods.h:16
obj::name
sstring name
Definition: object.h:317
sproto.h
liv::food
int32_t food
Definition: living.h:48
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
sounds.h
do_light
void do_light(object *item, const char *lighter_name, object *applier)
Definition: light_object.cpp:36
obj::type
uint8_t type
Definition: object.h:346
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
obj::stats
living stats
Definition: object.h:376
item
Definition: item.py:1
LIGHTER
@ LIGHTER
Definition: object.h:193
object_split
object * object_split(object *orig_ob, uint32_t nr, char *err, size_t size)
Definition: object.cpp:2631
obj::last_eat
int32_t last_eat
Definition: object.h:364
MSG_TYPE_APPLY_FAILURE
#define MSG_TYPE_APPLY_FAILURE
Definition: newclient.h:604
draw_ext_info
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.cpp:308
ob_methods.h
say.item
dictionary item
Definition: say.py:149
MSG_TYPE_APPLY
#define MSG_TYPE_APPLY
Definition: newclient.h:408
MSG_TYPE_APPLY_ERROR
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:601
find_marked_object
object * find_marked_object(object *op)
Definition: c_object.cpp:1520