Crossfire Server, Trunk  R20513
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  onoff, op->name);
61 
62  tmp2 = arch_to_object(op->other_arch);
63  tmp2->stats.food = op->stats.food;
64  if (QUERY_FLAG(op, FLAG_APPLIED))
65  CLEAR_FLAG(tmp2, FLAG_APPLIED);
66  else
67  SET_FLAG(tmp2, FLAG_APPLIED);
68  if (QUERY_FLAG(op, FLAG_INV_LOCKED))
70  object_insert_in_ob(tmp2, who);
71 
72  object_remove(op);
74 
75  fix_object(who);
76 
77  if (QUERY_FLAG(op, FLAG_CURSED) || QUERY_FLAG(op, FLAG_DAMNED)) {
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 
107 static method_ret lamp_type_apply(ob_methods *context, object *lamp, object *applier, int aflags) {
108  object *tmp;
109 
110  if (object_get_player_container(lamp) != applier) {
112  "You must get it first!\n");
113  return METHOD_ERROR;
114  }
115 
116  if (lamp->nrof > 1)
117  tmp = object_split(lamp, lamp->nrof-1, NULL, 0);
118  else
119  tmp = NULL;
120 
121  if (QUERY_FLAG(lamp, FLAG_APPLIED))
122  do_turn(lamp, applier, aflags, "off");
123  else {
124  if (lamp->stats.food < 1) {
125  if (!(aflags&AP_NOPRINT))
127  "Your %s is out of fuel!",
128  lamp->name);
129  return METHOD_OK;
130  }
131  do_turn(lamp, applier, aflags, "on");
132  }
133 
134  /* insert the portion that was split off. */
135  if (tmp != NULL) {
136  object_insert_in_ob(tmp, applier);
137  }
138 
139  return METHOD_OK;
140 }
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.
#define FLAG_DAMNED
The object is very cursed.
Definition: define.h:318
#define P_NEED_UPDATE
This space is out of date.
Definition: map.h:239
#define SET_FLAG(xyz, p)
Definition: define.h:223
Typedefs for ob_methods.
Definition: ob_methods.h:45
#define MSG_TYPE_APPLY_FAILURE
Apply OK, but no/bad result.
Definition: newclient.h:599
#define METHOD_ERROR
Definition: ob_methods.h:17
static method_ret lamp_type_apply(ob_methods *context, object *lighter, object *applier, int aflags)
Applies a lamp.
Definition: lamp.c:107
Global type definitions and header inclusions.
struct archt * other_arch
Pointer used for various things - mostly used for what this objects turns into or what this object cr...
Definition: object.h:413
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
void init_type_lamp(void)
Initializer for the LAMP object type.
Definition: lamp.c:39
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
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
Definition: object.c:1368
int16_t y
Position in the map for this object.
Definition: object.h:326
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
void update_all_los(const mapstruct *map, int x, int y)
This function makes sure that update_los() will be called for all players on the given map within the...
Definition: los.c:532
#define METHOD_OK
Definition: ob_methods.h:15
struct mapdef * map
Pointer to the map in which this object is present.
Definition: object.h:297
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:596
void update_position(mapstruct *m, int x, int y)
This function updates various attributes about a specific space on the map (what it looks like...
Definition: map.c:2119
const char * name
The name of the object, obviously...
Definition: object.h:311
static void do_turn(object *op, object *who, int aflags, const char *onoff)
Turn on/off the lamp, based on op&#39;s APPLIED status.
Definition: lamp.c:54
uint32_t nrof
How many of the objects.
Definition: object.h:333
#define AP_NOPRINT
Don&#39;t print messages - caller will do that may be some that still print.
Definition: define.h:621
void register_apply(int ob_type, apply_func method)
Registers the apply method for the given type.
Definition: ob_types.c:62
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
int16_t x
Definition: object.h:326
Lamp.
Definition: object.h:201
Object type variables.
#define FLAG_KNOWN_CURSED
The object is known to be cursed.
Definition: define.h:321
#define FLAG_CURSED
The object is cursed.
Definition: define.h:317
See Player.
Definition: object.h:107
#define SET_MAP_FLAGS(M, X, Y, C)
Sets map flags.
Definition: map.h:163
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
living stats
Str, Con, Dex, etc.
Definition: object.h:368
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
#define FLAG_APPLIED
Object is ready for use by living.
Definition: define.h:235
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 MSG_TYPE_APPLY_CURSED
Applied a cursed object (BAD)
Definition: newclient.h:600
#define NDI_UNIQUE
Print immediately, don&#39;t buffer.
Definition: newclient.h:245
Object type functions and variables.
#define FLAG_INV_LOCKED
Item will not be dropped from inventory.
Definition: define.h:330
void fix_object(object *op)
Updates all abilities given by applied objects in the inventory of the given object.
Definition: living.c:1120
object * arch_to_object(archetype *at)
Creates and returns a new object which is a copy of the given archetype.
Definition: arch.c:571
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to...
Definition: object.c:1654
int32_t food
How much food in stomach.
Definition: living.h:47