Atrinik Server  4.0
symptom.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 #include <arch.h>
36 
38 static void
39 process_func (object *op)
40 {
41  HARD_ASSERT(op != NULL);
42 
43  object *victim = op->env;
44  /* Outside a monster/player, die immediately */
45  if (victim == NULL || victim->map == NULL) {
46  object_remove(op, 0);
47  object_destroy(op);
48  return;
49  }
50 
51  victim = HEAD(victim);
52 
53  OBJECTS_DESTROYED_BEGIN(op, victim) {
54  if (op->stats.dam > 0) {
55  attack_hit(victim, op, op->stats.dam);
56  } else {
57  attack_hit(victim, op,
58  MAX(1.0, -victim->stats.maxhp * op->stats.dam / 100.0));
59  }
60 
61  if (OBJECTS_DESTROYED_ANY(op, victim)) {
62  return;
63  }
65 
66  int sp_reduce;
67  if (op->stats.maxsp > 0) {
68  sp_reduce = op->stats.maxsp;
69  } else {
70  sp_reduce = MAX(1.0, victim->stats.maxsp * op->stats.maxsp / 100.0);
71  }
72  victim->stats.sp = MAX(0, victim->stats.sp - sp_reduce);
73 
74  /* Create the symptom's "other arch" object and drop it here
75  * under every part of the monster. */
76 
77  if (op->other_arch != NULL) {
78  for (object *tmp = victim; tmp != NULL; tmp = tmp->more) {
79  object *new_ob = arch_to_object(op->other_arch);
80  new_ob->x = tmp->x;
81  new_ob->y = tmp->y;
82  new_ob->map = victim->map;
83  object_insert_map(new_ob,
84  victim->map,
85  victim,
87  }
88  }
89 
90  if (victim->type == PLAYER) {
91  draw_info(COLOR_RED, victim, op->msg);
92  }
93 }
94 
99 {
100  OBJECT_METHODS(SYMPTOM)->process_func = process_func;
101 }
void object_destroy(object *ob)
Definition: object.c:1441
OBJECT_TYPE_INIT_DEFINE(symptom)
Definition: symptom.c:98
#define PLAYER
Definition: define.h:122
int16_t sp
Definition: living.h:78
#define OBJECTS_DESTROYED_BEGIN(...)
Definition: object.h:765
struct archetype * other_arch
Definition: object.h:228
void object_remove(object *op, int flags)
Definition: object.c:1623
int16_t maxsp
Definition: living.h:81
int16_t y
Definition: object.h:276
int32_t maxhp
Definition: living.h:75
#define OBJECTS_DESTROYED_ANY(...)
Definition: object.h:782
struct mapdef * map
Definition: object.h:139
int16_t dam
Definition: living.h:87
struct obj * env
Definition: object.h:130
object * arch_to_object(archetype_t *at)
Definition: arch.c:446
#define INS_NO_WALK_ON
Definition: object.h:570
#define HEAD(op)
Definition: object.h:657
int16_t x
Definition: object.h:273
object * object_insert_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1741
#define OBJECTS_DESTROYED_END()
Definition: object.h:816
#define INS_NO_MERGE
Definition: object.h:564
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)
static void process_func(object *op)
Definition: symptom.c:39
const char * msg
Definition: object.h:183
#define SYMPTOM
Definition: define.h:542
struct obj * more
Definition: object.h:133