Atrinik Server  4.0
poisoning.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 <object.h>
34 #include <object_methods.h>
35 
37 static void
38 process_func (object *op)
39 {
40  HARD_ASSERT(op != NULL);
41 
42  if (op->env == NULL || !IS_LIVE(op->env) || op->env->stats.hp < 0) {
43  object_remove(op, 0);
44  object_destroy(op);
45  return;
46  }
47 
48  object *target = op->env;
49 
50  if (op->owner != NULL && !object_owner(op)) {
52  }
53 
54  OBJECTS_DESTROYED_BEGIN(target) {
55  if (!attack_hit(target, op, op->stats.dam)) {
56  return;
57  }
58 
59  if (OBJECTS_DESTROYED(target)) {
60  return;
61  }
63 
64  if (target->type != PLAYER) {
65  return;
66  }
67 
68  /* Pick some stats to 'deplete'. */
69  for (int i = 0; i < NUM_STATS; i++) {
70  if (rndm_chance(2) && get_attr_value(&op->stats, i) > -(MAX_STAT / 2)) {
71  /* Now deplete the stat. Relatively small chance that the
72  * depletion will be worse than usual. */
73  change_attr_value(&op->stats, i, rndm_chance(6) ? -2 : -1);
74  }
75  }
76 
77  living_update(target);
78 }
79 
84 {
85  OBJECT_METHODS(POISONING)->process_func = process_func;
86 }
void object_destroy(object *ob)
Definition: object.c:1441
#define IS_LIVE(op)
Definition: define.h:841
#define PLAYER
Definition: define.h:122
int8_t get_attr_value(const living *stats, int attr)
Definition: living.c:305
#define OBJECTS_DESTROYED_BEGIN(...)
Definition: object.h:765
static void process_func(object *op)
Definition: poisoning.c:38
#define POISONING
Definition: define.h:437
void object_remove(object *op, int flags)
Definition: object.c:1623
int32_t hp
Definition: living.h:72
OBJECT_TYPE_INIT_DEFINE(poisoning)
Definition: poisoning.c:83
int16_t dam
Definition: living.h:87
void change_attr_value(living *stats, int attr, int8_t value)
Definition: living.c:277
struct obj * env
Definition: object.h:130
#define OBJECTS_DESTROYED(obj)
Definition: object.h:811
#define NUM_STATS
Definition: living.h:49
#define OBJECTS_DESTROYED_END()
Definition: object.h:816
struct obj * owner
Definition: object.h:207
living stats
Definition: object.h:481
int attack_hit(object *op, object *hitter, int dam)
Definition: attack.c:669
uint8_t type
Definition: object.h:360
#define OBJECT_METHODS(type)
object * object_owner(object *op)
Definition: object.c:857
int living_update(object *op)
Definition: living.c:1661
void object_owner_clear(object *op)
Definition: object.c:741
#define MAX_STAT
Definition: define.h:47