Atrinik Server  4.0
light_apply.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
32 #include <global.h>
33 #include <arch.h>
34 #include <object_methods.h>
35 
37 static int
38 apply_func (object *op, object *applier, int aflags)
39 {
40  HARD_ASSERT(op != NULL);
41  HARD_ASSERT(applier != NULL);
42 
43  char *name = object_get_name_s(op, applier);
44 
45  if (op->glow_radius != 0 && op->env != NULL && op->env->type == PLAYER &&
46  !QUERY_FLAG(op, FLAG_APPLIED)) {
47  /* The object is lit and in player's inventory but it's not yet applied,
48  * so we just fall through and let the player equip the object. */
49  } else if (op->glow_radius != 0) {
50  op = object_stack_get_reinsert(op, 1);
51 
52  draw_info_format(COLOR_WHITE, applier,
53  "You extinguish the %s.",
54  name);
55 
57 
58  if (op->other_arch && op->other_arch->clone.sub_type & 1) {
60  esrv_update_item(UPD_FACE | UPD_ANIM, op);
61  } else {
63  esrv_update_item(UPD_FACE | UPD_ANIMSPEED, op);
64  }
65 
66  if (op->map != NULL) {
67  adjust_light_source(op->map, op->x, op->y, -op->glow_radius);
69  }
70 
71  op->glow_radius = 0;
72 
73  /* It's not applied, nothing else to do. */
74  if (!QUERY_FLAG(op, FLAG_APPLIED)) {
75  efree(name);
76  return OBJECT_METHOD_OK;
77  }
78  } else if (op->last_sp != 0) {
79  op = object_stack_get_reinsert(op, 1);
80 
81  draw_info_format(COLOR_WHITE, applier,
82  "You light the %s.",
83  name);
84 
85  /* Light source that burns out... */
86  if (op->last_eat != 0) {
88  }
89 
90  if (op->anim_speed != 0) {
93  esrv_update_item(UPD_FACE | UPD_ANIM | UPD_ANIMSPEED, op);
94  }
95 
96  op->glow_radius = op->last_sp;
97 
98  if (op->map != NULL) {
99  adjust_light_source(op->map, op->x, op->y, op->glow_radius);
101  }
102 
103  /* It's already applied, nothing else to do. */
104  if (QUERY_FLAG(op, FLAG_APPLIED)) {
105  efree(name);
106  return OBJECT_METHOD_OK;
107  }
108  } else {
109  draw_info_format(COLOR_WHITE, applier,
110  "The %s can't be lit.",
111  name);
112  efree(name);
113  return OBJECT_METHOD_OK;
114  }
115 
116  efree(name);
117 
118  if (op->env != NULL && op->env->type == PLAYER) {
119  /* Handle applying/unapplying the light. */
120  return object_apply_item(op, applier, aflags);
121  }
122 
123  return OBJECT_METHOD_OK;
124 }
125 
130 {
131  OBJECT_METHODS(LIGHT_APPLY)->apply_func = apply_func;
132 }
#define UP_OBJ_FACE
Definition: object.h:537
#define FLAG_ANIMATE
Definition: define.h:912
int16_t last_sp
Definition: object.h:313
#define PLAYER
Definition: define.h:122
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
struct archetype * arch
Definition: object.h:225
struct archetype * other_arch
Definition: object.h:228
char * object_get_name_s(const object *op, const object *caller)
Definition: item.c:398
int16_t y
Definition: object.h:276
void object_update(object *op, int action)
Definition: object.c:1117
uint16_t animation_id
Definition: object.h:322
struct mapdef * map
Definition: object.h:139
#define SET_FLAG(xyz, p)
Definition: define.h:741
struct obj * env
Definition: object.h:130
uint8_t anim_speed
Definition: object.h:393
int16_t x
Definition: object.h:273
void adjust_light_source(mapstruct *map, int x, int y, int light)
Definition: light.c:257
int16_t last_eat
Definition: object.h:319
#define LIGHT_APPLY
Definition: define.h:336
#define FLAG_APPLIED
Definition: define.h:1182
int object_apply_item(object *op, object *applier, int aflags)
Definition: apply.c:110
void esrv_update_item(int flags, object *op)
Definition: item.c:639
#define FLAG_CHANGING
Definition: define.h:988
uint8_t type
Definition: object.h:360
#define CLEAR_FLAG(xyz, p)
Definition: define.h:751
#define OBJECT_METHODS(type)
#define OBJECT_METHOD_OK
int8_t glow_radius
Definition: object.h:338
static int apply_func(object *op, object *applier, int aflags)
Definition: light_apply.c:38
OBJECT_TYPE_INIT_DEFINE(light_apply)
Definition: light_apply.c:129
object clone
An object from which to do object_copy().
Definition: arch.h:47
object * object_stack_get_reinsert(object *op, uint32_t nrof)
Definition: object.c:2046
uint8_t sub_type
Definition: object.h:363