Crossfire Server, Branches 1.12  R18729
lamp.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 
28 #include <global.h>
29 #include <ob_methods.h>
30 #include <ob_types.h>
31 #include <sounds.h>
32 #include <sproto.h>
33 
34 static method_ret lamp_type_apply(ob_methods *context, object *lighter, object *applier, int aflags);
35 
39 void init_type_lamp(void) {
41 }
42 
54 static void do_turn(object *op, object *who, int aflags, const char *onoff) {
55  object *tmp2;
56 
57  if (!(aflags&AP_NOPRINT))
59  "You turn %s your %s.",
60  NULL,
61  onoff, op->name);
62 
63  tmp2 = arch_to_object(op->other_arch);
64  tmp2->stats.food = op->stats.food;
65  if (QUERY_FLAG(op, FLAG_APPLIED))
66  CLEAR_FLAG(tmp2, FLAG_APPLIED);
67  else
68  SET_FLAG(tmp2, FLAG_APPLIED);
69  if (QUERY_FLAG(op, FLAG_INV_LOCKED))
71  insert_ob_in_ob(tmp2, who);
72 
73  remove_ob(op);
74  free_object(op);
75 
76  fix_object(who);
77 
78  if (QUERY_FLAG(op, FLAG_CURSED) || QUERY_FLAG(op, FLAG_DAMNED)) {
79  if (who->type == PLAYER) {
80  if (!(aflags&AP_NOPRINT))
82  "Oops, it feels deadly cold!", NULL);
84  }
85  }
86 
87  if (who->map) {
88  SET_MAP_FLAGS(who->map, who->x, who->y, P_NEED_UPDATE);
89  update_position(who->map, who->x, who->y);
90  update_all_los(who->map, who->x, who->y);
91  }
92 }
93 
108 static method_ret lamp_type_apply(ob_methods *context, object *lamp, object *applier, int aflags) {
109  object *tmp;
110 
111  if (get_player_container(lamp) != applier) {
113  "You must get it first!\n", NULL);
114  return METHOD_ERROR;
115  }
116 
117  if (lamp->nrof > 1)
118  tmp = get_split_ob(lamp, lamp->nrof-1, NULL, 0);
119  else
120  tmp = NULL;
121 
122  if (QUERY_FLAG(lamp, FLAG_APPLIED))
123  do_turn(lamp, applier, aflags, "off");
124  else {
125  if (lamp->stats.food < 1) {
126  if (!(aflags&AP_NOPRINT))
128  "Your %s is out of fuel!",
129  NULL,
130  lamp->name);
131  return METHOD_OK;
132  }
133  do_turn(lamp, applier, aflags, "on");
134  }
135 
136  /* insert the portion that was split off. */
137  if (tmp != NULL) {
138  insert_ob_in_ob(tmp, applier);
139  }
140 
141  return METHOD_OK;
142 }
#define FLAG_DAMNED
Definition: define.h:614
#define P_NEED_UPDATE
Definition: map.h:260
#define SET_FLAG(xyz, p)
Definition: define.h:510
#define MSG_TYPE_APPLY_FAILURE
Definition: newclient.h:519
#define METHOD_ERROR
Definition: ob_methods.h:44
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
sint16 x
Definition: object.h:179
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
static method_ret lamp_type_apply(ob_methods *context, object *lighter, object *applier, int aflags)
Definition: lamp.c:108
struct archt * other_arch
Definition: object.h:264
#define PLAYER
Definition: define.h:113
void init_type_lamp(void)
Definition: lamp.c:39
char method_ret
Definition: ob_methods.h:41
void remove_ob(object *op)
Definition: object.c:1515
object * get_player_container(object *op)
Definition: object.c:356
void update_all_los(const mapstruct *map, int x, int y)
Definition: los.c:544
#define METHOD_OK
Definition: ob_methods.h:42
struct mapdef * map
Definition: object.h:155
void update_position(mapstruct *m, int x, int y)
Definition: map.c:2124
const char * name
Definition: object.h:167
static void do_turn(object *op, object *who, int aflags, const char *onoff)
Definition: lamp.c:54
uint32 nrof
Definition: object.h:184
#define AP_NOPRINT
Definition: define.h:1020
sint16 y
Definition: object.h:179
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:79
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
#define CLEAR_FLAG(xyz, p)
Definition: define.h:512
#define MSG_TYPE_APPLY
Definition: newclient.h:330
object * insert_ob_in_ob(object *op, object *where)
Definition: object.c:2510
#define LAMP
Definition: define.h:263
#define FLAG_KNOWN_CURSED
Definition: define.h:617
#define MSG_TYPE_APPLY_CURSED
Definition: newclient.h:520
#define FLAG_CURSED
Definition: define.h:613
#define SET_MAP_FLAGS(M, X, Y, C)
Definition: map.h:184
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:518
living stats
Definition: object.h:219
#define FLAG_APPLIED
Definition: define.h:531
#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
void free_object(object *ob)
Definition: object.c:1238
#define FLAG_INV_LOCKED
Definition: define.h:626
void fix_object(object *op)
Definition: living.c:900
object * arch_to_object(archetype *at)
Definition: arch.c:576
uint8 type
Definition: object.h:189
sint32 food
Definition: living.h:89