Crossfire Server, Trunk
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(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  onoff, op->name);
61 
62  tmp2 = arch_to_object(op->other_arch);
63  tmp2->stats.food = op->stats.food;
65  CLEAR_FLAG(tmp2, FLAG_APPLIED);
66  else
67  SET_FLAG(tmp2, FLAG_APPLIED);
70  object_insert_in_ob(tmp2, who);
71 
74 
75  fix_object(who);
76 
78  if (who->type == PLAYER) {
79  if (!(aflags&AP_NOPRINT))
81  "Oops, it feels deadly cold!");
83  }
84  }
85 
86  if (who->map) {
87  SET_MAP_FLAGS(who->map, who->x, who->y, P_NEED_UPDATE);
88  update_position(who->map, who->x, who->y);
89  update_all_los(who->map, who->x, who->y);
90  }
91 }
92 
105 static method_ret lamp_type_apply(object *lamp, object *applier, int aflags) {
106  object *tmp;
107 
108  if (object_get_player_container(lamp) != applier) {
110  "You must get it first!\n");
111  return METHOD_ERROR;
112  }
113 
114  if (lamp->nrof > 1)
115  tmp = object_split(lamp, lamp->nrof-1, NULL, 0);
116  else
117  tmp = NULL;
118 
119  if (QUERY_FLAG(lamp, FLAG_APPLIED))
120  do_turn(lamp, applier, aflags, "off");
121  else {
122  if (lamp->stats.food < 1) {
123  if (!(aflags&AP_NOPRINT))
125  "Your %s is out of fuel!",
126  lamp->name);
127  return METHOD_OK;
128  }
129  do_turn(lamp, applier, aflags, "on");
130  }
131 
132  /* insert the portion that was split off. */
133  if (tmp != NULL) {
134  object_insert_in_ob(tmp, applier);
135  }
136 
137  return METHOD_OK;
138 }
PLAYER
@ PLAYER
Definition: object.h:107
global.h
object_remove
void object_remove(object *op)
Definition: object.c:1806
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
MSG_TYPE_APPLY_CURSED
#define MSG_TYPE_APPLY_CURSED
Definition: newclient.h:605
Ice.tmp
int tmp
Definition: Ice.py:207
do_turn
static void do_turn(object *op, object *who, int aflags, const char *onoff)
Definition: lamp.c:54
FLAG_INV_LOCKED
#define FLAG_INV_LOCKED
Definition: define.h:329
FLAG_APPLIED
#define FLAG_APPLIED
Definition: define.h:235
obj::nrof
uint32_t nrof
Definition: object.h:335
autojail.who
who
Definition: autojail.py:3
obj::name
sstring name
Definition: object.h:312
MSG_TYPE_APPLY_SUCCESS
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:603
FLAG_KNOWN_CURSED
#define FLAG_KNOWN_CURSED
Definition: define.h:320
FLAG_DAMNED
#define FLAG_DAMNED
Definition: define.h:317
SET_MAP_FLAGS
#define SET_MAP_FLAGS(M, X, Y, C)
Definition: map.h:164
fix_object
void fix_object(object *op)
Definition: living.c:1126
LAMP
@ LAMP
Definition: object.h:201
sproto.h
liv::food
int32_t food
Definition: living.h:48
register_apply
void register_apply(int ob_type, apply_func method)
Definition: ob_types.c:62
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
sounds.h
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
obj::stats
living stats
Definition: object.h:371
P_NEED_UPDATE
#define P_NEED_UPDATE
Definition: map.h:240
give.op
op
Definition: give.py:33
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
AP_NOPRINT
#define AP_NOPRINT
Definition: define.h:585
object_insert_in_ob
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2820
update_all_los
void update_all_los(const mapstruct *map, int x, int y)
Definition: los.c:536
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:232
lamp_type_apply
static method_ret lamp_type_apply(object *lighter, object *applier, int aflags)
Definition: lamp.c:105
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.c:309
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.c:1533
update_position
void update_position(mapstruct *m, int x, int y)
Definition: map.c:2123
METHOD_ERROR
#define METHOD_ERROR
Definition: ob_methods.h:17
ob_methods.h
object_get_player_container
object * object_get_player_container(object *op)
Definition: object.c:600
MSG_TYPE_APPLY
#define MSG_TYPE_APPLY
Definition: newclient.h:408
FLAG_CURSED
#define FLAG_CURSED
Definition: define.h:316
MSG_TYPE_APPLY_ERROR
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:601
init_type_lamp
void init_type_lamp(void)
Definition: lamp.c:39
object_split
object * object_split(object *orig_ob, uint32_t nr, char *err, size_t size)
Definition: object.c:2600
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,...)
Definition: main.c:319