Crossfire Server, Trunk  R20513
lighter.c
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(ob_methods *context, object *lighter, object *applier, int aflags);
28 
32 void init_type_lighter(void) {
34 }
35 
54 static method_ret lighter_type_apply(ob_methods *context, object *lighter, object *applier, int aflags) {
55  object *item;
56  int is_player_env = 0;
57  uint32_t nrof;
58  tag_t count;
59  char item_name[MAX_BUF];
60 
61  if (applier->type != PLAYER)
62  return METHOD_UNHANDLED;
63 
64  item = find_marked_object(applier);
65  if (!item) {
67  "You need to mark a lightable object.");
68  return METHOD_OK;
69  }
70 
71  if (lighter->last_eat && lighter->stats.food) {
72  /* Split multiple lighters if they're being used up. Otherwise
73  * one charge from each would be used up. --DAMN
74  */
75  if (lighter->nrof > 1) {
76  object *oneLighter = object_split(lighter, 1, NULL, 0);
77 
78  oneLighter->stats.food--;
79  oneLighter = object_insert_in_ob(oneLighter, applier);
80  } else {
81  lighter->stats.food--;
82  }
83  } else if (lighter->last_eat) { /* no charges left in lighter */
85  "You fail to light the %s with a used up %s.",
86  item->name, lighter->name);
87  return METHOD_OK;
88  }
89 
90  /* Perhaps we should split what we are trying to light on fire?
91  * I can't see many times when you would want to light multiple
92  * objects at once. */
93  nrof = item->nrof;
94  count = item->count;
95  /* If the item is destroyed, we don't have a valid pointer to the
96  * name object, so make a copy so the message we print out makes
97  * some sense. */
98  safe_strncpy(item_name, item->name, sizeof(item_name));
99  if (applier == object_get_player_container(item))
100  is_player_env = 1;
101 
102  save_throw_object(item, AT_FIRE, applier);
103 
104  /* Change to check count and not freed, since the object pointer
105  * may have gotten recycled */
106  if ((nrof != item->nrof) || (count != item->count)) {
108  "You light the %s with the %s.",
109  item_name, lighter->name);
110 
111  /* Need to update the player so that the players glow radius
112  * gets changed. */
113  if (is_player_env)
114  fix_object(applier);
115  } else {
117  "You attempt to light the %s with the %s and fail.",
118  item->name, lighter->name);
119  }
120 
121  return METHOD_OK;
122 }
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Sends message to player(s).
Definition: main.c:315
Sound-related defines.
Typedefs for ob_methods.
Definition: ob_methods.h:45
#define MSG_TYPE_APPLY_FAILURE
Apply OK, but no/bad result.
Definition: newclient.h:599
static method_ret lighter_type_apply(ob_methods *context, object *lighter, object *applier, int aflags)
Attempts to apply a lighter.
Definition: lighter.c:54
Global type definitions and header inclusions.
#define safe_strncpy
Definition: compat.h:23
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Sends message to player(s).
Definition: main.c:310
#define MSG_TYPE_APPLY
Applying objects.
Definition: newclient.h:384
char method_ret
Define some standard return values for callbacks which don&#39;t need to return any other results...
Definition: ob_methods.h:14
object * object_insert_in_ob(object *op, object *where)
This function inserts the object op in the linked list inside the object environment.
Definition: object.c:2690
#define METHOD_OK
Definition: ob_methods.h:15
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:596
const char * name
The name of the object, obviously...
Definition: object.h:311
uint32_t nrof
How many of the objects.
Definition: object.h:333
void register_apply(int ob_type, apply_func method)
Registers the apply method for the given type.
Definition: ob_types.c:62
#define AT_FIRE
Definition: attack.h:78
object * find_marked_object(object *op)
Return the object the player has marked with the &#39;mark&#39; command below.
Definition: c_object.c:1256
uint32_t tag_t
Object tag, unique during the whole game.
Definition: object.h:12
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
#define METHOD_UNHANDLED
Definition: ob_methods.h:16
int32_t last_eat
How long since we last ate.
Definition: object.h:356
Object type variables.
void save_throw_object(object *op, uint32_t type, object *originator)
Object is attacked with some attacktype (fire, ice, ...).
Definition: attack.c:156
See Player.
Definition: object.h:107
unsigned int uint32_t
Definition: win32.h:162
void init_type_lighter(void)
Initializer for the LIGHTER object type.
Definition: lighter.c:32
object * object_split(object *orig_ob, uint32_t nr, char *err, size_t size)
object_split(ob,nr) splits up ob into two parts.
Definition: object.c:2463
tag_t count
Unique object number for this object.
Definition: object.h:299
living stats
Str, Con, Dex, etc.
Definition: object.h:368
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
object * object_get_player_container(object *op)
Finds the player carrying an object.
Definition: object.c:353
#define MSG_TYPE_APPLY_SUCCESS
Was able to apply object.
Definition: newclient.h:598
#define NDI_UNIQUE
Print immediately, don&#39;t buffer.
Definition: newclient.h:245
Object type functions and variables.
void fix_object(object *op)
Updates all abilities given by applied objects in the inventory of the given object.
Definition: living.c:1120
int32_t food
How much food in stomach.
Definition: living.h:47