Crossfire Server, Branches 1.12  R18729
lighter.c
Go to the documentation of this file.
1 /*
2  CrossFire, A Multiplayer game for X-windows
3 
4  Copyright (C) 2007 Crossfire Development Team
5  Copyright (C) 1992 Frank Tore Johansen
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21  The authors can be reached via e-mail at crossfire-devel@real-time.com
22 */
23 
27 #include <global.h>
28 #include <ob_methods.h>
29 #include <ob_types.h>
30 #include <sounds.h>
31 #include <sproto.h>
32 
33 static method_ret lighter_type_apply(ob_methods *context, object *lighter, object *applier, int aflags);
34 
38 void init_type_lighter(void) {
40 }
41 
60 static method_ret lighter_type_apply(ob_methods *context, object *lighter, object *applier, int aflags) {
61  object *item;
62  int is_player_env = 0;
63  uint32 nrof;
64  tag_t count;
65  char item_name[MAX_BUF];
66 
67  if (applier->type != PLAYER)
68  return METHOD_UNHANDLED;
69 
70  item = find_marked_object(applier);
71  if (!item) {
73  "You need to mark a lightable object.", NULL);
74  return METHOD_OK;
75  }
76 
77  if (lighter->last_eat && lighter->stats.food) {
78  /* Split multiple lighters if they're being used up. Otherwise
79  * one charge from each would be used up. --DAMN
80  */
81  if (lighter->nrof > 1) {
82  object *oneLighter = get_split_ob(lighter, 1, NULL, 0);
83 
84  oneLighter->stats.food--;
85  oneLighter = insert_ob_in_ob(oneLighter, applier);
86  } else {
87  lighter->stats.food--;
88  }
89  } else if (lighter->last_eat) { /* no charges left in lighter */
91  "You fail to light the %s with a used up %s.",
92  NULL,
93  item->name, lighter->name);
94  return METHOD_OK;
95  }
96 
97  /* Perhaps we should split what we are trying to light on fire?
98  * I can't see many times when you would want to light multiple
99  * objects at once. */
100  nrof = item->nrof;
101  count = item->count;
102  /* If the item is destroyed, we don't have a valid pointer to the
103  * name object, so make a copy so the message we print out makes
104  * some sense. */
105  strncpy(item_name, item->name, sizeof(item_name));
106  if (applier == get_player_container(item))
107  is_player_env = 1;
108 
109  save_throw_object(item, AT_FIRE, applier);
110 
111  /* Change to check count and not freed, since the object pointer
112  * may have gotten recycled */
113  if ((nrof != item->nrof) || (count != item->count)) {
115  "You light the %s with the %s.",
116  NULL,
117  item_name, lighter->name);
118 
119  /* Need to update the player so that the players glow radius
120  * gets changed. */
121  if (is_player_env)
122  fix_object(applier);
123  } else {
125  "You attempt to light the %s with the %s and fail.",
126  NULL,
127  item->name, lighter->name);
128  }
129 
130  return METHOD_OK;
131 }
void save_throw_object(object *op, uint32 type, object *originator)
Definition: attack.c:171
#define MSG_TYPE_APPLY_FAILURE
Definition: newclient.h:519
#define LIGHTER
Definition: define.h:237
static method_ret lighter_type_apply(ob_methods *context, object *lighter, object *applier, int aflags)
Definition: lighter.c:60
void draw_ext_info(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
Definition: standalone.c:171
void draw_ext_info_format(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *new_format, const char *old_format,...)
Definition: standalone.c:175
#define PLAYER
Definition: define.h:113
char method_ret
Definition: ob_methods.h:41
uint32 tag_t
Definition: object.h:40
object * get_player_container(object *op)
Definition: object.c:356
#define METHOD_OK
Definition: ob_methods.h:42
const char * name
Definition: object.h:167
uint32 nrof
Definition: object.h:184
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:79
#define AT_FIRE
Definition: attack.h:106
object * find_marked_object(object *op)
Definition: c_object.c:1339
#define MSG_TYPE_APPLY
Definition: newclient.h:330
object * insert_ob_in_ob(object *op, object *where)
Definition: object.c:2510
#define MAX_BUF
Definition: define.h:81
#define METHOD_UNHANDLED
Definition: ob_methods.h:43
sint32 last_eat
Definition: object.h:207
void init_type_lighter(void)
Definition: lighter.c:38
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:518
tag_t count
Definition: object.h:157
living stats
Definition: object.h:219
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:516
#define NDI_UNIQUE
Definition: newclient.h:219
object * get_split_ob(object *orig_ob, uint32 nr, char *err, size_t size)
Definition: object.c:2313
unsigned int uint32
Definition: global.h:58
void fix_object(object *op)
Definition: living.c:900
uint8 type
Definition: object.h:189
sint32 food
Definition: living.h:89