Crossfire Server, Trunk  1.75.0
light_object.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2021 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 
20 #include "global.h"
21 #include "sproto.h"
22 
36 void do_light(object *item, const char *lighter_name, object *applier) {
37  int is_player_env = 0;
38  tag_t count;
39  char item_name[MAX_BUF];
40  uint32_t nrof;
41  /* Perhaps we should split what we are trying to light on fire?
42  * I can't see many times when you would want to light multiple
43  * objects at once. */
44  nrof = item->nrof;
45  count = item->count;
46  /* If the item is destroyed, we don't have a valid pointer to the
47  * name object, so make a copy so the message we print out makes
48  * some sense. */
49  safe_strncpy(item_name, item->name, sizeof(item_name));
50  if (applier == object_get_player_container(item))
51  is_player_env = 1;
52 
53  save_throw_object(item, AT_FIRE, applier);
54 
55  /* Change to check count and not freed, since the object pointer
56  * may have gotten recycled */
57  if ((nrof != item->nrof) || (count != item->count)) {
59  "You light the %s with the %s.",
60  item_name, lighter_name);
61 
62  /* Need to update the player so that the players glow radius
63  * gets changed. */
64  if (is_player_env)
65  fix_object(applier);
66  } else {
68  "You attempt to light the %s with the %s and fail.",
69  item->name, lighter_name);
70  }
71 }
global.h
safe_strncpy
#define safe_strncpy
Definition: compat.h:27
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
object::count
tag_t count
Unique object number for this object.
Definition: object.h:307
fix_object
void fix_object(object *op)
Updates all abilities given by applied objects in the inventory of the given object.
Definition: living.cpp:1132
MSG_TYPE_APPLY_SUCCESS
#define MSG_TYPE_APPLY_SUCCESS
Was able to apply object.
Definition: newclient.h:607
do_light
void do_light(object *item, const char *lighter_name, object *applier)
Common code for both lighting an item for applying the lighter and for lighting the lightable object.
Definition: light_object.cpp:36
tag_t
uint32_t tag_t
Object tag, unique during the whole game.
Definition: object.h:14
sproto.h
MAX_BUF
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
NDI_UNIQUE
#define NDI_UNIQUE
Print immediately, don't buffer.
Definition: newclient.h:266
object::name
sstring name
The name of the object, obviously...
Definition: object.h:319
MSG_TYPE_APPLY_FAILURE
#define MSG_TYPE_APPLY_FAILURE
Apply OK, but no/bad result.
Definition: newclient.h:608
object::nrof
uint32_t nrof
Number of objects.
Definition: object.h:342
save_throw_object
void save_throw_object(object *op, uint32_t type, object *originator)
Object is attacked with some attacktype (fire, ice, ...).
Definition: attack.cpp:202
MSG_TYPE_APPLY
#define MSG_TYPE_APPLY
Applying objects.
Definition: newclient.h:412
object_get_player_container
object * object_get_player_container(object *op)
Finds the player carrying an object.
Definition: object.cpp:592
AT_FIRE
#define AT_FIRE
Definition: attack.h:78