Atrinik Server  4.0
cone.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 
51 static bool
52 cone_exists (object *op, mapstruct *m, int x, int y)
53 {
54  FOR_MAP_PREPARE(m, x, y, tmp) {
55  if (op->type == tmp->type && op->weight_limit == tmp->weight_limit) {
56  return true;
57  }
58  } FOR_MAP_FINISH();
59 
60  return false;
61 }
62 
64 static void process_func(object *op)
65 {
66  HARD_ASSERT(op != NULL);
67 
68  if (op->map == NULL) {
69  return;
70  }
71 
72  if (QUERY_FLAG(op, FLAG_LIFESAVE)) {
73  attack_hit_map(op, 0, false);
74  return;
75  }
76 
77  attack_hit_map(op, 0, true);
78 
79  op->stats.hp -= 2;
80  if (op->stats.hp < 0) {
81  object_remove(op, 0);
82  object_destroy(op);
83  return;
84  }
85 
86  if (op->stats.food != 0) {
87  return;
88  }
89 
90  op->stats.food = 1;
91 
92  for (int i = -1; i < 2; i++) {
93  int x = op->x + freearr_x[absdir(op->stats.sp + i)];
94  int y = op->y + freearr_y[absdir(op->stats.sp + i)];
95  mapstruct *m = get_map_from_coord(op->map, &x, &y);
96  if (m == NULL) {
97  continue;
98  }
99 
100  if (wall(m, x, y) || cone_exists(op, m, x, y)) {
101  continue;
102  }
103 
104  /* Create the next part of the cone. */
105  object *tmp = arch_to_object(op->arch);
106  object_owner_copy(tmp, op);
107  tmp->weight_limit = op->weight_limit;
108  tmp->x = x;
109  tmp->y = y;
110  tmp->level = op->level;
111  tmp->stats.sp = op->stats.sp;
112  tmp->stats.hp = op->stats.hp + 1;
113  tmp->stats.maxhp = op->stats.maxhp;
114  tmp->stats.dam = op->stats.dam;
115 
116  tmp = object_insert_map(tmp, m, op, 0);
117  if (tmp == NULL) {
118  continue;
119  }
120  }
121 }
122 
124 static int
125 move_on_func (object *op, object *victim, object *originator, int state)
126 {
127  HARD_ASSERT(op != NULL);
128  HARD_ASSERT(victim != NULL);
129 
130  if (state == 0) {
131  return OBJECT_METHOD_OK;
132  }
133 
134  if (QUERY_FLAG(op, FLAG_SLOW_MOVE)) {
135  return OBJECT_METHOD_OK;
136  }
137 
138  if (IS_LIVE(victim)) {
139  attack_hit(victim, op, op->stats.dam);
140  }
141 
142  return OBJECT_METHOD_OK;
143 }
144 
149 {
150  OBJECT_METHODS(CONE)->move_on_func = move_on_func;
151  OBJECT_METHODS(CONE)->process_func = process_func;
152 }
#define CONE
Definition: define.h:385
void object_destroy(object *ob)
Definition: object.c:1441
static bool cone_exists(object *op, mapstruct *m, int x, int y)
Definition: cone.c:52
mapstruct * get_map_from_coord(mapstruct *m, int *x, int *y)
Definition: map.c:1869
int wall(mapstruct *m, int x, int y)
Definition: map.c:486
static int move_on_func(object *op, object *victim, object *originator, int state)
Definition: cone.c:125
void attack_hit_map(object *op, int dir, bool multi_reduce)
Definition: attack.c:830
OBJECT_TYPE_INIT_DEFINE(cone)
Definition: cone.c:148
static int absdir(int d)
Definition: define.h:1838
#define IS_LIVE(op)
Definition: define.h:841
int16_t sp
Definition: living.h:78
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
struct archetype * arch
Definition: object.h:225
void object_remove(object *op, int flags)
Definition: object.c:1623
#define FLAG_SLOW_MOVE
Definition: define.h:916
int32_t hp
Definition: living.h:72
int16_t y
Definition: object.h:276
int32_t maxhp
Definition: living.h:75
#define FLAG_LIFESAVE
Definition: define.h:1125
struct mapdef * map
Definition: object.h:139
int16_t dam
Definition: living.h:87
object * arch_to_object(archetype_t *at)
Definition: arch.c:446
#define FOR_MAP_FINISH()
Definition: define.h:1759
int16_t x
Definition: object.h:273
object * object_insert_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1741
uint32_t weight_limit
Definition: object.h:252
living stats
Definition: object.h:481
int attack_hit(object *op, object *hitter, int dam)
Definition: attack.c:669
int freearr_x[SIZEOFFREE]
Definition: object.c:84
uint8_t type
Definition: object.h:360
#define OBJECT_METHODS(type)
#define OBJECT_METHOD_OK
Definition: map.h:536
int8_t level
Definition: object.h:347
int freearr_y[SIZEOFFREE]
Definition: object.c:99
void object_owner_copy(object *op, object *clone_ob)
Definition: object.c:824
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:1752
int16_t food
Definition: living.h:84
static void process_func(object *op)
Definition: cone.c:64