Atrinik Server  4.0
process.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 
40 static void common_object_process_changing(object *op)
41 {
42  object *tmp, *env;
43 
44  if (op->stats.food-- > 0) {
45  return;
46  }
47 
48  /* Handle applyable lights that should burn out. */
49  if (op->type == LIGHT_APPLY) {
51 
52  /* Inform the player, if the object is inside player's inventory. */
53  if (op->env && op->env->type == PLAYER) {
54  char *name = object_get_name_s(op, op->env);
55  draw_info_format(COLOR_WHITE, op->env, "The %s burnt out.", name);
56  efree(name);
57  }
58 
59  /* If other_arch is not set, it means the light can be refilled
60  * (such as a lamp) and doesn't need to be exchanged with another
61  * object (such as torch becoming a burned out torch). */
62  if (!op->other_arch) {
63  if (op->other_arch && op->other_arch->clone.sub_type & 1) {
65  SET_ANIMATION(op, (NUM_ANIMATIONS(op) / NUM_FACINGS(op)) * op->direction);
66  } else {
68  op->face = op->arch->clone.face;
69  }
70 
71  /* Is it in inventory? */
72  if (op->env) {
73  op->glow_radius = 0;
74  esrv_send_item(op);
75 
76  /* Inside player? */
77  if (op->env->type == PLAYER) {
78  /* Will take care about adjusting light masks. */
79  living_update(op->env);
80  }
81  } else {
82  /* Object is on map. */
83 
84  /* Remove light mask from map. */
85  adjust_light_source(op->map, op->x, op->y, -(op->glow_radius));
87  op->glow_radius = 0;
88  }
89 
90  return;
91  }
92  }
93 
94  if (!op->other_arch) {
95  LOG(BUG, "%s is missing other_arch.", op->name);
96  return;
97  }
98 
99  env = op->env;
100  object_remove(op, 0);
101 
102  tmp = arch_to_object(op->other_arch);
103 
104  if (env) {
105  object_insert_into(tmp, env, 0);
106  } else {
107  tmp->x = op->x;
108  tmp->y = op->y;
109  object_insert_map(tmp, op->map, op, 0);
110  }
111 
112  object_destroy(op);
113 }
114 
124 {
125  if (QUERY_FLAG(op, FLAG_CHANGING) && !op->state) {
127  return 1;
128  }
129 
130  if (QUERY_FLAG(op, FLAG_IS_USED_UP) && --op->stats.food <= 0) {
131  /* Handle corpses specially. */
132  if (op->type == CONTAINER && op->sub_type == ST1_CONTAINER_CORPSE) {
133  /* If the corpse is currently open by someone, delay the
134  * corpse removal for a bit longer. */
135  if (op->attacked_by) {
136  /* Give him a bit time back */
137  op->stats.food += 3;
138  return 1;
139  }
140 
141  /* If the corpse was locked, remove the lock, making it
142  * available available for all players, and reset the decay
143  * counter. */
144  if (op->slaying || op->stats.maxhp) {
145  if (op->slaying) {
147  }
148 
149  op->stats.maxhp = 0;
150  op->stats.food = op->arch->clone.stats.food;
151  return 1;
152  }
153  }
154 
155  object_remove(op, 0);
156  object_destroy(op);
157 
158  return 1;
159  }
160 
161  return 0;
162 }
163 
165 void common_object_process(object *op)
166 {
167  if (OBJECT_IS_PROJECTILE(op)) {
169  }
170 }
void object_destroy(object *ob)
Definition: object.c:1441
#define UP_OBJ_FACE
Definition: object.h:537
#define NUM_FACINGS(ob)
Definition: global.h:300
#define FLAG_ANIMATE
Definition: define.h:912
#define SET_ANIMATION(ob, newanim)
Definition: global.h:282
const char * slaying
Definition: object.h:180
#define OBJECT_IS_PROJECTILE(ob)
Definition: object.h:823
#define ST1_CONTAINER_CORPSE
Definition: define.h:568
#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
void object_remove(object *op, int flags)
Definition: object.c:1623
char * object_get_name_s(const object *op, const object *caller)
Definition: item.c:398
int16_t y
Definition: object.h:276
int32_t maxhp
Definition: living.h:75
void object_update(object *op, int action)
Definition: object.c:1117
int8_t direction
Definition: object.h:350
uint16_t animation_id
Definition: object.h:322
object * object_insert_into(object *op, object *where, int flag)
Definition: object.c:2158
struct mapdef * map
Definition: object.h:139
const char * name
Definition: object.h:168
struct obj * env
Definition: object.h:130
void common_object_process(object *op)
Definition: process.c:165
uint8_t state
Definition: object.h:344
object * arch_to_object(archetype_t *at)
Definition: arch.c:446
#define CONTAINER
Definition: define.h:493
#define FLAG_IS_USED_UP
Definition: define.h:976
void esrv_send_item(object *op)
Definition: item.c:703
int16_t x
Definition: object.h:273
void adjust_light_source(mapstruct *map, int x, int y, int light)
Definition: light.c:257
static void common_object_process_changing(object *op)
Definition: process.c:40
object * object_insert_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1741
#define LIGHT_APPLY
Definition: define.h:336
int common_object_process_pre(object *op)
Definition: process.c:123
#define NUM_ANIMATIONS(ob)
Definition: global.h:298
living stats
Definition: object.h:481
#define FLAG_CHANGING
Definition: define.h:988
uint8_t type
Definition: object.h:360
#define CLEAR_FLAG(xyz, p)
Definition: define.h:751
int living_update(object *op)
Definition: living.c:1661
int8_t glow_radius
Definition: object.h:338
New_Face * face
Definition: object.h:234
object clone
An object from which to do object_copy().
Definition: arch.h:47
void common_object_projectile_process(object *op)
Definition: projectile.c:68
#define FREE_AND_CLEAR_HASH2(_nv_)
Definition: global.h:162
struct obj * attacked_by
Definition: object.h:199
int16_t food
Definition: living.h:84
uint8_t sub_type
Definition: object.h:363